is there a way to connect the sys_id of a record producer with the sys_id of the record produced?

patricklatella
Mega Sage

I'm trying to figure out a way to connect the sys_id of a request record to the sys_id of the record producer that created it.

is that possible?

1 ACCEPTED SOLUTION

Michael Fry1
Kilo Patron

In the script field of the record producer you can add code to populate a field with the information you want. For example, say you have a field RC on incident table, where RC is a reference to the record producer table. In the script field in the RC, you can use current. u_rc = 'sys_id' of record producer.


View solution in original post

11 REPLIES 11

Michael Fry1
Kilo Patron

In the script field of the record producer you can add code to populate a field with the information you want. For example, say you have a field RC on incident table, where RC is a reference to the record producer table. In the script field in the RC, you can use current. u_rc = 'sys_id' of record producer.


Michael Ritchie
ServiceNow Employee
ServiceNow Employee

What release are you on?   Istanbul includes a new table that links a record producer to the record generated:


Service Catalog release notes


lSurya 24
Giga Guru

Hello Patrick,



write the below script in your record producer script area:


current.fieldname = current.sys_id; // field name should be reference field which is created on the table where record is being created. And reference field should point to catalog item table.


patricklatella
Mega Sage

thanks everyone...actually working using case script on the UI Action that is looking up with the request template and setting the var to a sysID for the URL string I need.   However it's not quite working, anyone see what might be wrong?   This is supposed to be defining the var "sysID", then building the URL for the UI Action with the var "url", and then adding the var "sysID", and then adding some parameters to populate some fields on the new form.   The issues seems to be that it's not liking the



url=url+sysID+'&sysparm_'+gr.question.name+'='+gr.value;




however here's the full script:



var sysID;



switch (current.template){


case 'db5f551b4fca6e0089c7029d0210c7d9'://sys_id of Contract template


sysID='3e4c5d974fca6e0089c7029d0210c79d';//sys_id of Contracts record producer


break;



case '7481334c4f3db60089c7029d0210c72d'://sys_id of Cost Accounting template


sysID='3891bb4c4f3db60089c7029d0210c725';//sys_id of Cost Accounting record producer


break;



case 'b7fe73444f7db60089c7029d0210c72a'://sys_id of Business Development template


sysID='400f73444f7db60089c7029d0210c72c';//sys_id of BD PM record producer


break;


}



var url;


url = '/com.glideapp.servicecatalog_cat_item_view.do?sysparm_initial=true&sysparm_id=';//url to build string upon



var gr= new GlideRecord("question_answer");//table to query


gr.addQuery('table_sys_id',current.sys_id);//field to query


gr.query();//execute the query



while (gr.next()){


if (gr.question.name == 'project_type' || gr.question.name == 'request_type' || gr.question.name == 'sales_org' || gr.question.name == 'responsible_person' || gr.question.name == 'pfo_employee' || gr.question.name == 'customer_type')



url=url+sysID+'&sysparm_'+gr.question.name+'='+gr.value;



}


action.setRedirectURL(url);