I am developing an interface using the REST driver where the target system stores certain field values (like Department, for instance) as foreign key values (as opposed to the string value that is stored in eDirectory).

I have successfully implemented policies on the subscriber channel to query the target system, retrieve the key for the Department name, and reformat the operation attribute. That policy is as follows:
	<do-set-local-variable name="department-id" scope="policy">
			<token-query class-name="Department">
				<arg-match-attr name="Name">
					<arg-value type="string">
						<token-op-attr name="Title"/>
					<token-text xml:space="preserve">InstanceId</token-text>
	<do-reformat-op-attr name="Department">
		<arg-value type="string">
			<token-local-variable name="department-id"/>
However, the challenge is that not all Department values may exist in the target system when the users are getting added and/or modified. In those cases, the initial query returns nothing so I need to add a new value to the Department table in the destination, get the resulting key and then reformat the users department attribute.

I am able to initiate an add event for the new department, which returns the key on the subsequent status event but I cant figure out how to retrieve that value and reformat the attribute in the initial operation.

Can someone out there chime in on the high-level logic and/or proper tokens that could be used to accomplish this?