Script Include Reference Qualifier on Record Producer and on Record

bradfournier
Kilo Expert

I wrote a Script Include, u_filterFormsWorkflows, to filter a reference field on a record producer. It is called on the field using 'javascript:u_filterFormsWorkflows()'. It works perfectly on the record producer, so I tried to use the script include again as the reference qualifier for the same field but on the actual record this time. Here, it does not work. I'm calling it again using 'javascript:u_filterFormsWorkflows()', but also tried it without the javascript tag.

Part of me also thinks that it's because I had to use 'current.variables.u_form_workflow_department' to call to a field on the record producer, and my guess is that 'current.variables' doesn't work on a record itself. Below is the Script Include for reference.

Should I be able to use the same script include as the reference qualifier on both a record producer and a record, or do I need two different scripts?

function u_filterFormsWorkflows(){

  var fawList = ' ';

  var dept = current.variables.u_form_workflow_department;

  var faw = new GlideRecord('u_sharepoint_forms_and_workflows');

 

  faw.addQuery('u_department', dept);

  faw.query();

     

  while(faw.next()) {

            if (fawList.length > 0) {

                      fawList += (',' + faw.sys_id);

            }

            else {

                      fawList = faw.sys_id;

                      }

  }

  return 'sys_idIN' + fawList;

}

1 ACCEPTED SOLUTION

Chuck Tomasi
Tera Patron

The real question is:



is u_form_workflow_department a field or a variable on the resulting record? I suspect it's a mapped variable-->field so current.variables isn't going to work.



How about you pass that value in via the record producer and use it the same in both cases.



The record producer can call it like this:



javascript:u_filterFormsWorkflows(current.variables.u_form_workflow_department);



The resulting record would use the field value as an argument.



Also, instead of "building" a comma separated list, use an array and join the values at the end. Much simpler.



function u_filterFormsWorkflows(dept){  


  var fawList = [];  


  var dept = ;  


  var faw = new GlideRecord('u_sharepoint_forms_and_workflows');  


     


  faw.addQuery('u_department', dept);  


  faw.query();  


         


  while(faw.next()) {


            fawList.push(faw.getValue('sys_id'));


  }



  return 'sys_idIN' + fawList.join(',);  


}  


View solution in original post

3 REPLIES 3

Chuck Tomasi
Tera Patron

The real question is:



is u_form_workflow_department a field or a variable on the resulting record? I suspect it's a mapped variable-->field so current.variables isn't going to work.



How about you pass that value in via the record producer and use it the same in both cases.



The record producer can call it like this:



javascript:u_filterFormsWorkflows(current.variables.u_form_workflow_department);



The resulting record would use the field value as an argument.



Also, instead of "building" a comma separated list, use an array and join the values at the end. Much simpler.



function u_filterFormsWorkflows(dept){  


  var fawList = [];  


  var dept = ;  


  var faw = new GlideRecord('u_sharepoint_forms_and_workflows');  


     


  faw.addQuery('u_department', dept);  


  faw.query();  


         


  while(faw.next()) {


            fawList.push(faw.getValue('sys_id'));


  }



  return 'sys_idIN' + fawList.join(',);  


}  


Ah, I hadn't even thought of passing the variable like that. I just tested and it works perfectly.



Thanks Chuck!


I've been doing far too much scripting this week - lots of parameters making lots of code turn in to little code.