Use GlideRecord setLimit(3) and need to save all three records to different fields of another table.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎11-26-2018 08:59 PM
Dear Expert,
Could you please help me on this? I wrote a business rule to get value/display value from variable of application form to another table for report purpose. The script was set to run under condition once the request state is "Close Complete".
I query from sys_approval table and each request has three approval, however I want to save all three approvers to different fields such approver1 to field1, approver2 to field2 and approver3 to field3 but how can I do that? Any one can help me?.
The follow code it only return with same value/approver.
// Query from sysapproval and insert to the table
var recSysapproval = new GlideRecord('sysapproval_approver');
recSysapproval.addQuery('sysapproval', current.sys_id);
recSysapproval.addQuery('state', "Approved");
recSysapproval.orderByDesc('sys_created_on');
recSysapproval.setLimit(3);
recSysapproval.query();
while (recSysapproval.next()){
var grvendor = new GlideRecord('u_vendor_master_data_aging_report');
grvendor.initialize();
grvendor.u_tsc_number = current.sys_id;
grvendor.u_legal_appr_date = recSysapproval.sys_updated_on;
grvendor.u_legal_approver = recSysapproval.approver.getDisplayValue();
grvendor.u_sup_appr_date = recSysapproval.sys_updated_on;
grvendor.u_sup_approver = recSysapproval.approver.getDisplayValue();
grvendor.u_tsc_appr_date = recSysapproval.sys_updated_on;
grvendor.u_tsc_approver = recSysapproval.approver.getDisplayValue();
grvendor.u_company_code = current.variables.Company.getDisplayValue();
grvendor.u_vendor_name = current.variables.vendor_name.getDisplayValue();
grvendor.u_vendor_code = current.variables.vendor_code.getDisplayValue();
grvendor.u_currency = current.variables.Currency.getDisplayValue();
grvendor.u_type = current.variables.re_type.getDisplayValue();
grvendor.u_request_date = current.variables.re_date.getDisplayValue();
grvendor.insert();
gs.addInfoMessage('-- The approvers were added!!');
}
Really appreciate for your help.
Regards,
Cheng
- Labels:
-
Scripting and Coding

- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎11-26-2018 09:25 PM
Hi,
You can do like below
var recSysapproval = new GlideRecord('sysapproval_approver');
recSysapproval.addQuery('sysapproval', current.sys_id);
recSysapproval.addQuery('state', "Approved");
recSysapproval.orderByDesc('sys_created_on');
recSysapproval.setLimit(3);
recSysapproval.query();
while (recSysapproval.next()){
var grvendor = new GlideRecord('u_vendor_master_data_aging_report');
grvendor.addQuery('u_tsc_number', current.sys_id);
if(grvendor.next()){
grvendor.u_legal_appr_date = recSysapproval.sys_updated_on;
grvendor.u_legal_approver = recSysapproval.approver.getDisplayValue();
grvendor.u_sup_appr_date = recSysapproval.sys_updated_on;
grvendor.u_sup_approver = recSysapproval.approver.getDisplayValue();
grvendor.u_tsc_appr_date = recSysapproval.sys_updated_on;
grvendor.u_tsc_approver = recSysapproval.approver.getDisplayValue();
grvendor.u_company_code = current.variables.Company.getDisplayValue();
grvendor.u_vendor_name = current.variables.vendor_name.getDisplayValue();
grvendor.u_vendor_code = current.variables.vendor_code.getDisplayValue();
grvendor.u_currency = current.variables.Currency.getDisplayValue();
grvendor.u_type = current.variables.re_type.getDisplayValue();
grvendor.u_request_date = current.variables.re_date.getDisplayValue();
grvendor.update();
gs.addInfoMessage('-- The approvers created!!');
}
}
else
{
grvendor.initialize();
grvendor.u_tsc_number = current.sys_id;
grvendor.u_legal_appr_date = recSysapproval.sys_updated_on;
grvendor.u_legal_approver = recSysapproval.approver.getDisplayValue();
grvendor.u_sup_appr_date = recSysapproval.sys_updated_on;
grvendor.u_sup_approver = recSysapproval.approver.getDisplayValue();
grvendor.u_tsc_appr_date = recSysapproval.sys_updated_on;
grvendor.u_tsc_approver = recSysapproval.approver.getDisplayValue();
grvendor.u_company_code = current.variables.Company.getDisplayValue();
grvendor.u_vendor_name = current.variables.vendor_name.getDisplayValue();
grvendor.u_vendor_code = current.variables.vendor_code.getDisplayValue();
grvendor.u_currency = current.variables.Currency.getDisplayValue();
grvendor.u_type = current.variables.re_type.getDisplayValue();
grvendor.u_request_date = current.variables.re_date.getDisplayValue();
grvendor.insert();
gs.addInfoMessage('-- The approvers were updated!!');
}

- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎11-28-2018 01:25 AM
Hi chenglo,
Please mark correct answer if my reply helped you.

- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎11-26-2018 10:18 PM
One of the ways that you can try is to loop through the approval table and push the approvers to an array. Later, use the array to push the records to any other table that you want.