'Invalid Return'

Josh80
Tera Expert

Hello all

I'm trying to learn scripting...the script below will be used in an approval workflow; the purpose is to look up a custom table/record 'u_customer' and look to see if

a checkbox is marked true.   If so, return 'true', build approval.   What I have below is just resulting in an error with 'invalid return'.

I see where others have solved similar errors by 'wrapping it in a function'.   I'm not sure how to do that here.

Any suggestions?

Thanks

var grM2M = new GlideRecord('u_m2m_change_requests_customer');

grM2M.addQuery('u_change_request', current.sys_id.toString());

grM2M.query();

while(grM2M.next())

{

      var grCustomer = new GlideRecord('u_customer');

      if(grCustomer.get(grM2M.u_customer.toString()))

      {

             

  if(grCustomer.u_exec_approval == true){

                 

  return;

  }

}

}

1 ACCEPTED SOLUTION

Thanks Pradeep.



I got it to work with the following:



answer = [];




var grM2M = new GlideRecord('u_m2m_change_requests_customer');


grM2M.addQuery('u_change_request', current.sys_id.toString());


grM2M.query();




while(grM2M.next())


{


      var grCustomer = new GlideRecord('u_customer');


      if(grCustomer.get(grM2M.u_customer.toString()))


        {


           


  if(grCustomer.u_exec_approval == true){


 



  answer.push('f1a48da94f9d8200f90f01b28110c7e7');





  }


}


}


View solution in original post

6 REPLIES 6

Pradeep Sharma
ServiceNow Employee
ServiceNow Employee

Hi Josh,



There was an error in your code. Please go through the below code and modify it according to your req.


var grM2M = new GlideRecord('u_m2m_change_requests_customer');


grM2M.addQuery('u_change_request', current.sys_id.toString());


grM2M.query();



while(grM2M.next())


{


      var grCustomer = new GlideRecord('u_customer');


      if(grCustomer.get('columnname',grM2M.u_customer.toString())) //Here replace columnname with the field column name


      {


           


  if(grCustomer.u_exec_approval == true){


               


  return true;



  }


}


}



Please let me know if you have any questions.


Hello Pradeep



Thank you for your response.



I've modified the script accordingly and it is still resulting in an


'invalid return'.



The 'u_m2m_change_requests_customer' table is a custom 'join' table between


change requests and the u_customer table.


The script should grab the u_m2m table, thus the change request and look at


the related customer...and then the column 'u_exec_approval'. If it's


true, then approval group should be applied...if not, skip.



I see that I'm actually missing the code that will push the specific


approval group to string (if the u_exec_approval field is true).


The group sys_id is f1a48da94f9d8200f90f01b28110c7e7. That's a big piece,


but not sure if I have to query it or just push it.




var grM2M = new GlideRecord('u_m2m_change_requests_customer');


grM2M.addQuery('u_change_request', current.sys_id.toString());


grM2M.query();



while(grM2M.next())


{


var grCustomer = new GlideRecord('u_customer');


if(grCustomer.get('u_exec_approval',grM2M.u_customer.toString()))


{



if(grCustomer.u_exec_approval == true){



return true;



}


}


}



On Sun, Jul 19, 2015 at 1:09 PM, Pradeep Sharma <


Hello Pradeep


Thank you for your response.



I've modified the script accordingly and it is still resulting in an 'invalid return'.


The 'u_m2m_change_requests_customer' table is a custom 'join' table between change requests and the u_customer table.


The script should grab the u_m2m table, thus the change request and look at the related customer...and then the column 'u_exec_approval'.   If it's true, then approval group should be applied...if not, skip.



I see that I'm actually missing the code that will push the specific approval group to string (if the u_exec_approval field is true).


The group sys_id is f1a48da94f9d8200f90f01b28110c7e7.   That's a big piece, but not sure if I have to query it or just push it.



var grM2M = new GlideRecord('u_m2m_change_requests_customer');


grM2M.addQuery('u_change_request', current.sys_id.toString());


grM2M.query();


while(grM2M.next())


{


      var grCustomer = new GlideRecord('u_customer');


      if(grCustomer.get('u_exec_approval',grM2M.u_customer.toString()))





      {


           


  if(grCustomer.u_exec_approval == true){


               


  return true;


  }


}


}


Hi Josh,



Please refer the below thread for more info.


https://community.servicenow.com/thread/189005