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

patricklatella
Mega Sage

could I set the condition to aim at a script include and use the script include somehow to find the sys_id of the 3 record producers?


patricklatella
Mega Sage

or would that just be the same as putting the script directly in the UI Action?


Hmm.. what release are you on? I think that table came with Istanbul.



If you go to "request reports" like this. Do you have a report called "[catalog] Created by Record Producers"?


find_real_file.png



Yea, it will be the same thing, but in a script include you can reuse the code for other stuff as well.


patricklatella
Mega Sage

we are on Helsinki


patricklatella
Mega Sage

for anyone reading through this thread, I ended up solving my question with the following:  



The condition to qualify the record producer in the UI Action so the button only shows on specific records was:



current.template=='db5f551b4fca6e0089c7029d0210c7d9' || current.template=='7481334c4f3db60089c7029d0210c72d' || current.template=='b7fe73444f7db60089c7029d0210c72a'//these are the sys_ids of the record producer I wanted to show the button on






The script that built the URL needed to copy various fields to populate on the new form was:



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



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



}



gs.addInfoMessage('+++My URL is '+url);//this here for testing purposes


action.setRedirectURL(url);





and the catalog client script to populate the values on the new form onLoad was:



function onLoad() {


      //Populate the variables with the parameters passed in the URL


      //Use the 'getParmVal' function below to get the parameter values from the URL



var customertype = getParmVal('sysparm_customer_type');//for customer_type


      if(customertype){


            g_form.setValue('customer_type',customertype);


      }



var ptvalue = getParmVal('sysparm_project_type');//for project_type


      if(ptvalue){


            g_form.setValue('project_type',ptvalue);


      }



var rtvalue = getParmVal('sysparm_request_type');//for request_type


      if(rtvalue){


            g_form.setValue('request_type',rtvalue);


      }



var resp = getParmVal('sysparm_responsible_person');//for person responsible


      if(resp){


            g_form.setValue('responsible_person',resp);


      }



var pfo = getParmVal('sysparm_pfo_employee');//for applicant, PFO


      if(pfo){


  g_form.setValue('pfo_employee',pfo);


  }


}


function getParmVal(name){


        var url = document.URL.parseQuery();


if(url[name]){


                return decodeURI(url[name]);


        }


        else{


                return;


        }



}