Attempting to grab RITM variable and transferring value to a field

kristenmkar
Mega Sage

Good evening! 

I may be overthinking this, but I am trying to grab a variable submitted via the service catalog from the ritm, and place that value into a field located on a different table. This field resides in a custom table and is dot-walked onto the request form. I attempted a business rule utilizing the current.variables format (i.e. gr.dotwalkedfieldfromrequest =  current.variables.test_variable) but realized that won't work with a dot-walked field. Should I try a glide record maybe? 

any suggestions are appreciated! 🙂 

 

Thank you!

1 ACCEPTED SOLUTION

Ankur Bawiskar
Tera Patron
Tera Patron

@kristenmkar 

you can have after insert BR on RITM table

How is that custom table related to REQ?

You should use proper query in your GlideRecord when you query that table

Condition: current.cat_item.name == 'Your Catalog Item Name Here'

Script:

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

    // Add your code here
    var gr = new GlideRecord("yourtableName");
    gr.addQuery("sys_id", 'sysIdHere');
    gr.query();
    if (gr.next()) {
        gr.u_field = current.variables.variableName;
        gr.update();
    }

})(current, previous);

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

View solution in original post

4 REPLIES 4

Ankur Bawiskar
Tera Patron
Tera Patron

@kristenmkar 

you can have after insert BR on RITM table

How is that custom table related to REQ?

You should use proper query in your GlideRecord when you query that table

Condition: current.cat_item.name == 'Your Catalog Item Name Here'

Script:

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

    // Add your code here
    var gr = new GlideRecord("yourtableName");
    gr.addQuery("sys_id", 'sysIdHere');
    gr.query();
    if (gr.next()) {
        gr.u_field = current.variables.variableName;
        gr.update();
    }

})(current, previous);

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

Just what I needed, thank you so much! 

Sorry, I have a quick follow-up question! I realized I didn't respond to your question about the relationship from the custom table to the REQ table - which I think is confusing me now (haha).  I have a reference field on REQ which points to the custom table and allows me to dot-walk into the custom table fields from req. I also use this reference field within a UI policy to create a gliderecord to display the custom fields within the REQ based on the catalog item.   I am trying to figure out the proper query to use from the RITM Gliderecord - do I need an additional reference field on my custom table to point to the RITM? I thought i could potentially use this but it doesn't seem to work:

 

    // push bfm to request from variables
    var gr = new GlideRecord("u_addtl_request_details_bco_wireless");
    gr.addQuery("sysid", current.u_addtl_details_bco_wireless_ref);
    gr.query();
    if (gr.next()) {
        gr.u_bfm_name = current.variables.bfm_name;
        gr.update();
    }
 
Thanks!

Hi Ankur Bawiskar,

I have tried to place the RITM variable value to the REQ short description. But the value is not setting to it. I am sending my code here:

(function executeRule(current, previous /*null when async*/) {
 
    var gr = new GlideRecord("sc_request");
    gr.addQuery("sys_id", current.request);
    gr.query();
    if (gr.next()) {
        gr.short_description = current.variables.summary;
        gr.update();
    }
   
})(current, previous);