how do I query the sys_id of the record producer from a created record with a UI Action?

patricklatella
Mega Sage

I've got a UI Action I'm using to create a copy of a form from a request record.   I have 3 different types of record producers that will be using the "Copy Form" UI Action, and I want the UI Action to know which record producer to go to.  

I've got the following script for the UI Action.

var url;

url = '/com.glideapp.servicecatalog_cat_item_view.do?sysparm_initial=true&sysparm_id=3e4c5d974fca6e0089c7029d0210c79d';//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+'&sysparm_'+gr.question.name+'='+gr.value;

}

action.setRedirectURL(url);

You see that currently the sys_id of the record producer is hard coded into the "var url".   What I want to do is to pull that sys_id out and rather have the UI Action query the record (or something like that) to know the sys_id of the record producer that create the request and have it link to that.

Here's what I've got so far (I know it's wrong but hopefully it helps you see what I'm shooting to do)

var url;

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

var sysID;//THIS IS PART I NEED HELP WITH

sysID=(current.sys_id);//THIS IS THE PART I NEED HELP WITH

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);

1 ACCEPTED SOLUTION

Hmm.. so if you create a record through them, it doesn't log it in the "sc_item_produced_record" table? If that doesn't happen, I think another way is to have a hidden variable with the sys_id of the RP in it or have a field on the table where the record is being created and then in the RP script put the RP sys_id in that field.


View solution in original post

9 REPLIES 9

Goran WitchDoc
ServiceNow Employee
ServiceNow Employee

Are we talking about a request(sc_request) or a requested item(sc_req_item)? because the requested item has a field called cat_item which is a reference field holding the sys_id from where it was created. and if it was created through a record producer you can look in the table ""sc_item_produced_record" to see which Record producer created the specific record/task.


patricklatella
Mega Sage

Hi Goran, thanks for the reply.



The 3 record producers are all in a scoped application on the following table, [x_cur_erp_sm_request] which is extended from the Service Order table, [sm_order]


Hmm.. so if you create a record through them, it doesn't log it in the "sc_item_produced_record" table? If that doesn't happen, I think another way is to have a hidden variable with the sys_id of the RP in it or have a field on the table where the record is being created and then in the RP script put the RP sys_id in that field.


patricklatella
Mega Sage

not sure...when I type sc_item_produced_record.list in the menu filter I get this



find_real_file.png