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

Hello Patrick,



Can you post the sample URL for which you want to redirect. May be help us debug better


patricklatella
Mega Sage

to clarify, with this script the UI Action is linking back to the previous page, which was the list of request records "Created by me".   So not sure if it's linking directly (on purpose I mean), or if it's just somewhat mimicking a "back" button.


patricklatella
Mega Sage

sure, if you look at this script you can see the URL string I'm shooting to build for the UI Action.   In this script, however the sys_id of the record producer is hard coded.   This script works, however I need it to direct to one of 3 record producers specificlaly, based on the template sys_id that is attached to the record I'm looking to create the "Copy Form" for.



so this script works...and if you compare with the initial script in this thread you can see what I'm shooting to accomplish.





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')//these are the values that will populate on the new form



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


}



action.setRedirectURL(url);




And to clarify, this is the script I'm trying to get to do what I need, and right now it's just bringing up a blank page with "Not authorized" written in the upper left corner.



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


patricklatella
Mega Sage

OK so I believe I am getting close.   This script properly bringing up the correct record producer (based on the record producer that created the original request record to copy the form).   However it is now jumbling the URL it's creating and adding the record producer sys_id to the URL after each variable value that is showing correctly in the URL.   Something about my lines in bold?



var ID;



switch (current.template.toString()){


case 'db5f551b4fca6e0089c7029d0210c7d9'://sys_id of Contract template


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


break;



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


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


break;



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


ID = '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 == 'responsible_person' || gr.question.name == 'pfo_employee' || gr.question.name == 'customer_type')



url=url+ID+'&sysparm_'+gr.question.name+'='+gr.value;//something wrong here?   it's generating the URL below with the added sys_id of record producer being inserted after each gr.value??



}



gs.addInfoMessage('+++My URL is '+url);


action.setRedirectURL(url);





here's the URL this UI Action is generating.   Now oddly you'll notice it is NOT adding the sys_id of the record producer after the last variable in the URL string.   Clue?



/com.glideapp.servicecatalog_cat_item_view.do?sysparm_initial=true&sysparm_id=3e4c5d974fca6e0089c7029d0210c79d&sysparm_project_type=Standard Direct3e4c5d974fca6e0089c7029d0210c79d&sysparm_request_type=new3e4c5d974fca6e0089c7029d0210c79d&sysparm_responsible_person=1f3bb2864f2602004100029d0210c76c3e4c5d974fca6e0089c7029d0210c79d&sysparm_pfo_employee=413b72864f2602004100029d0210c7783e4c5d974fca6e0089c7029d0210c79d&sysparm_customer_type=us government


patricklatella
Mega Sage

ok I've definitely isolated the problem down to this line:



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



what it's doing is inserting whatever is in the space where "ID" is, into the URL after every gr.value, except for the last one.   So it's putting where it should be, after the value of whatever "url" is determined to be...but then also again and again in the URL string....but not at the very end.



any know why this would do this?