- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
07-19-2015 09:06 AM
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;
}
}
}
Solved! Go to Solution.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
07-19-2015 11:14 AM
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');
}
}
}
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
07-19-2015 11:14 AM
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');
}
}
}
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
07-21-2015 09:16 AM
that's just a basic javascript problem, you can't return unless your inside a function. An example with your code might look like:
var answer = requiresExecApproval() ? [ 'f1a48da94f9d8200f90f01b28110c7e7' ] : [];
function requiresExecApproval() {
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)
return true;
}
}
return false;
}
the advantage of directly returning inside a while loop is that you can short circuit the loop and skip unneeded iterations.