Populating ServiceNow variable through the Workflow

MuhammadAqS
Tera Contributor

I have a Workflow script, that is assigning values to different variables. Below is that script:

var grReqItem = new GlideRecord('sc_req_item');
    grReqItem.addQuery('request', current.request);
    grReqItem.addQuery('cat_item', sysid);
    grReqItem.orderByDesc('sys_created_on');
    grReqItem.query();

    if (grReqItem.next()) {
        // Reset the parent and summary fields
        grReqItem.parent = ''; // Don't need parent as they are linked via request
        grReqItem.short_description = 'IT New Starter Application Permissions for ' + current.variables.u_first_name + ' ' + current.variables.u_last_name + ' - ' + current.variables.u_start_date.toString();
       
        // Set the non conditional fields first
        grReqItem.variables.u_first_name = current.variables.u_first_name   ;
        grReqItem.variables.u_last_name = current.variables.u_last_name;
        grReqItem.variables.u_job_title = current.variables.u_title;
        grReqItem.variables.u_start_date = current.variables.u_start_date;
        grReqItem.variables.u_additional_it_requirements = current.variables.u_additional_requirements;
        grReqItem.variables.u_location = current.variables.u_location;
        grReqItem.variables.u_manager = current.variables.u_manager;
        grReqItem.variables.u_user_name = current.variables.u_user_name;
        grReqItem.variables.u_email = current.variables.u_email;


I have created a new variable Approval to Hire ID, and I want to assign this value also. I've written the below line but that's not working:

grReqItem.variables.u_approval_to_hire_id = current.variables.u_approval_to_hire_id;


19 REPLIES 19

@MuhammadAqS 

are you sure when you open the form the variable has value in it?

share that RITM record where variable editor shows that variable

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

yes, it has value in it. But it's not showing on the RITM. Below is the screenshot:

MuhammadAqS_0-1738849294042.png

 

this is the full output:

*** Script: Approval to Hire ID from Producer: 
*** Script: Found RITM: RITM0042665
*** Script: :white_heavy_check_mark: Approval to Hire ID updated successfully for RITM: RITM0042665

PritamG
Mega Guru

Use setValue() to assign the variable value explicitly and ensure the record is updated 

grReqItem.setValue('variables.u_approval_to_hire_id', current.variables.u_approval_to_hire_id);
grReqItem.update();

also, check if u_approval_to_hire_id  exists in both catalog items. 

Hi @PritamG,

I've tried this too, but it's not working.