Set catalog variable value to a field on table

smahmud
Tera Contributor
Spoiler
 

I created a new custom field called "Activity" on the sc_req_item table for reporting purposes. We have a "universal" variable throughout most of our catalog items called "Select Action Type". I want this "Select Action Type" field's value to populate in the "Activity" field so that a user could easily report on the "Activity" field for all catalog items. This is the client script I wrote, but it's not working, can someone tell me what I'm doing wrong?

 

 

 

function onSubmit() {
   var actionType = g_form.getValue('select_action_type');
   g_form.setValue('u_activity', actionType);
}

 

 

4 REPLIES 4

Ankur Bawiskar
Tera Patron
Tera Patron

@smahmud 

you can use after insert business rule and set

current.u_activity = current.variables.select_action_type;
current.setWorkflow(false);
current.update();

If my response helped please mark it correct and close the thread so that it benefits future readers.

Regards,
Ankur
Certified Technical Architect  ||  9x ServiceNow MVP  ||  ServiceNow Community Leader

@smahmud 

Hope you are doing good.

Did my reply answer your question?

If my response helped please mark it correct and close the thread so that it benefits future readers.

Regards,
Ankur
Certified Technical Architect  ||  9x ServiceNow MVP  ||  ServiceNow Community Leader

Brian Lancaster
Tera Sage

Is this a catalog client script? If so it does not have access to the fields on the sc_req_item table. Also g_form only work if the field is visible on the form. So your custom field would not be visible on the form when the request is submitted.

You best bet would be to do a before insert business rule on the sc_req_item table. The code would be simple as below.

 

(function executeRule(current, previous /*null when async*/) {

	current.u_activity = current.variables.select_action_type;

})(current, previous);

 

 

Voona Rohila
Kilo Patron
Kilo Patron

Hi @smahmud 

 

You can write before insert BR on RITM Table to update the Activity field

 

if(current.variables.select_action_type.toString() != '' )
current.u_activity = current.variables.select_action_type;

 

Add proper conditions to your BR so that it triggers for specific catalog items which has action type variable.

 

If It's for a single catalog item then you can simply use 'Update record' action in your catalog flow.


Mark it helpful if this helps you to understand. Accept solution if this give you the answer you're looking for
Kind Regards,
Rohila V
2022-25 ServiceNow Community MVP