Adding to a List from a Lookup on a Freedom UI Page

In my previous article I outlined how to invoke a lookup dialog on a Freedom UI page. In this article, we’ll expand on that idea to allow adding to a list from a lookup. For this sample, we have a list on the account page of products owned by the account. We’ll add a button to invoke a lookup to allow the user to select one or multiple products to add to the account’s product list.

The end result will be as follows:

The code to accomplish this will be very similar to the previous article. The main difference will be that instead of flattening out the text values of the selected items, we’ll use a model Insert to add the records.

View Inserting a Record from Client-Side Code Using the Model Class

Note, first make sure you’re adding the Creatio devkit to the page as sdk (see article above). The code for the request of the click of our button will look like this:

request.$context.executeRequest({
	type: "crt.OpenLookupPageRequest",
	$context: request.$context,
	entitySchemaName: "Product",
	caption: "Select products to add to the account",
	features: {
		select: {
			multiple: true,
			selectAll: false,
			resultType: 'lookupValues'
		},
		create: {
			enabled: false
		}
	},
	afterClosed: async function(selectedItems) {
		// add each selected item from the lookup to the list
		
		const accountId = await request.$context.Id;
		const accountProdModel = await sdk.Model.create("UsrAccountProduct");
							
		selectedItems.forEach(product => {
			accountProdModel.insert({
				UsrAccount: accountId,
				UsrProduct: product.value
			});
		});
	}
});

To make it so the items appear in the list without the need to refresh it, simply enable live data update for the entity you’re adding to.

ABOUT THE AUTHOR

Ryan Farley

Ryan Farley is the Director of Development for Customer FX and creator of slxdeveloper.com. He's been blogging regularly about SalesLogix, now Infor CRM, since 2001 and believes in sharing with the community. His new passion for CRM is Creatio, formerly bpm'online. He loves C#, Javascript, web development, open source, and Linux. He also loves his hobby as an amateur filmmaker.

2 Comments

  1. Information on how to add this custom code to the action of when a button is clicked would be useful. I think there is another CustomerFX article on it that could be used to link to for this purpose.

    Reply

Submit a Comment

Your email address will not be published. Required fields are marked *

Subscribe To Our Newsletter

Join our mailing list to receive the latest Infor CRM (Saleslogix) and Creatio (bpm'online) news and product updates!

You have Successfully Subscribed!