The CreatorCon Call for Content is officially open! Get started here.

How to populate an embedded list with a script? (advanced scripting needed)

Smith Johnson
Tera Guru

Hello all,

I would like to know how can I populate an embedded list. For example, in the following image, all fields of the form (request form) can be populated with a mapping between user's selections and table's fields. However, there is no any option for making a mapping between a record producer's option and a column of an embedded list.

In my case, I want once a user selects an item on Service Portal, this item is populated and appears on the embedded list of the record.

find_real_file.png

I guess it needs advanced scripting techniques, but since I don't have them your assistance would be incredibly valuable for me.

Thank you in advance for your time and your willingness to help me.

Best regards,

Smith.

1 ACCEPTED SOLUTION

To use the cart functionality - test with one catalog item you can pick from the record producer.

1. Add a new variable to the catalog item

  • Type: Reference
  • Table: sc_request

2. Add a UI Policy to hide the variable on load

3. In the BR you have in the REQ table, replace the code with this: 

var cartId = GlideGuid.generate(null);
var cart = new Cart(cartId);
var item = cart.addItem(current.u_cat_item); 
cart.setVarible(item, 'request', current.sys_id);
var rc = cart.placeOrder(); 

View solution in original post

22 REPLIES 22

You're very welcome! 🙂 Let me know how it turns out!

@YenGar You are definitely my hero!! It works!! 

find_real_file.png

The embedded list is populated.

However the workflow is not triggered. It seems that the first stage of the workflow is done, but I don't understand why the next stages are not triggered.

 

find_real_file.png

 

You can't imagine how grateful I feel for your assistance!! Really thank you for all the time that you spent on this thread trying to figure out my logic and provide me a solution!! 

I hope you could help me also trigger the workflow.

Thank you again and again.

Regards,

Smith.

@YenGar 

Here is also an image that maybe will help you understand what's going on. The workflow is not triggered for this item (even if I have a workflow attached on this item).

I don't know what's going on.

Even if all the stages are just a log message activity, they are not triggered.

Maybe I need to try the option with the cart that you said, but to be honest I didn't understand it.

find_real_file.png

If we could find again a solution to this, I would be so grateful for your help.

Hi Smith, 

Sorry for the late response on this! I was afraid that would happen. Did you add the ritm.setWorkflow(true); after the insert on the BR? It should look like this:

var cat = current.u_cat_item; //catalog item selected 
var ritm = new GlideRecord('sc_req_item');
ritm.initialize();
ritm.request = current.sys_id; //associate the REQ to the RITM
ritm.quantity = '1';
ritm.item = cat; //populate Item with the user's selection
ritm.insert();
ritm.setWorkflow(true);
gs.log("RITM Inserted: " + ritm);

Give that a try and let me know if it works. If it still has issues starting the workflow, then we can go the cart route. We'll work through it 🙂

 

Yeny

To use the cart functionality - test with one catalog item you can pick from the record producer.

1. Add a new variable to the catalog item

  • Type: Reference
  • Table: sc_request

2. Add a UI Policy to hide the variable on load

3. In the BR you have in the REQ table, replace the code with this: 

var cartId = GlideGuid.generate(null);
var cart = new Cart(cartId);
var item = cart.addItem(current.u_cat_item); 
cart.setVarible(item, 'request', current.sys_id);
var rc = cart.placeOrder();