How to Set Quote Owner

The following code shows how to set a quote owner. It can be useful e.g. in an integration scenario when IntegrationManager handles the revisions. Without this code, the quote would be owned by IntegrationManager and this information would be passed to 3rd party systems (which is not ideal for audit or tracking purposes).

function void updateQuoteOwner(String uniqueName, int userId) {

	// fetch existing quote to update quote owner
	// in case of creation, use price operation
	Response resp = priceFxClient.getQuoteApi().fetch(uniqueName);

	if (resp != null && resp.getResponse() != null) {
   		ArrayList quotes = (ArrayList) resp.getResponse().getData();
    	Map<String, Object> quote = (Map<String, Object>) quotes.get(0);
    
    	// set/update quote owner by his/her userId through 'createdBy' field
    	quote.put("createdBy", userId);

    	// save the update to Pfx
    	priceFxClient.getQuoteApi().save(new SaveQuoteRequest().data(new PriceQuoteRequestData().quote(quote)));
	}
}