- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎08-27-2024 11:10 PM
Hi All,
I have written the below code. Output is coming correctly. How should I return the sys_id so that it should visible in the reference qualifier field.
getProduct: function() {
var accounts = current.account;
var platform = current.u_platform;
var subProd = current.getDisplayValue("u_sub_products");
var ur = new GlideRecord("u_sub_product");
ur .addEncodedQuery('u_sub_product=' + subProd + '^u_platform=' + platform);
ur .query();
while (ur .next()) {
var user_array = [];
var product_array = user_array.push(ur.u_product);
}
var dee = new GlideRecord("sn_install_base_sold_product");
dee.addEncodedQuery("u_platform=" + platform + "^account=" + accounts);
dee.query();
while (dee.next()) {
var prod_array = [];
var arr = prod_array.push(dee.name);
if (JSON.stringify(product_array) == JSON.stringify(arr)) {
gs.log("OUTPUT RESULTS" + dee.sys_id);
} else {
gs.log("FALSE RESULT");
}
}
return dee.sys_id;
},
The return value should populate in the Product field(reference to Sold Product table (sn_install_base_sold_product).
Please help me.
Thanks,
Sam
Solved! Go to Solution.
- Labels:
-
compliance
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎08-28-2024 10:31 AM
Hi @Samiksha2 ,
In the above you are comparing the jason, try comparing the arrays and also print the product array and the arr and attach the screen shot of the result,
getProduct: function() {
var accounts = current.account;
var platform = current.u_platform;
var subProd = current.getDisplayValue("u_sub_products");
var ur = new GlideRecord("u_sub_product");
var user_array = [];
ur.addEncodedQuery('u_sub_product=' + subProd + '^u_platform=' + platform);
ur.query();
while (ur.next()) {
user_array.push(ur.u_product.toString());
}
var dee = new GlideRecord("sn_install_base_sold_product");
dee.addEncodedQuery("u_platform=" + platform + "^account=" + accounts);
dee.query();
var arrForSysID = [];
var prod_array = [];
while (dee.next()) {
prod_array.push(dee.name.toString());
function areArraysEqual(array1, array2) {
for (var i = 0; i < array2.length; i++) {
if (array1.indexOf(array2[i]) === -1) {
return false;
}
}
return true;
}
var result = areArraysEqual(user_array, prod_array);
if (result == true || result == 'true') {
gs.log("OUTPUT RESULTS" + dee.sys_id);
arrForSysID.push(dee.getValue('sys_id'));
} else {
gs.log("FALSE RESULT");
}
}
gs.info('Product array ' + user_array);
gs.info('arr ' + prod_array);
gs.info('Final sysId ' + arrForSysID);
return 'sys_idIN' + arrForSysID;
},
please share the logs,
Please mark this comment as Correct Answer/Helpful if it helped you.
Regards,
Swathi Sarang

- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎08-28-2024 05:11 AM
@Samiksha2 Can you confirm if
u_product
Is a string or a reference field?
(JSON.stringify(product_array) == JSON.stringify(arr))
As in product array we have an array of u_product (which may be sys_ids if u_product is a reference field) and on the other side arr contains a list of names the comparison may fail.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎08-28-2024 05:15 AM
Hi @Sandeep Rajput ,
In Sub Product table product is String value and in the Sold product it is sys id that's why i am returning name
var prod_array = []; var arr = prod_array.push(dee.name);
In the logs correct values are coming but it is returning only one value.
Thanks,
Sam
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎08-28-2024 05:34 AM
Hi @Samiksha2 ,
Replace the line "var arr = prod_array.push(dee.name);" with below,
var arr = prod_array.push(dee.name.toString();
or
var arr = prod_array.push(dee.getValue('name);
and while returning use return 'sys_idIN' + arr ;
or
i have updated your code please give it a try,
getProduct: function() {
var accounts = current.account;
var platform = current.u_platform;
var subProd = current.getDisplayValue("u_sub_products");
var ur = new GlideRecord("u_sub_product");
ur.addEncodedQuery('u_sub_product=' + subProd + '^u_platform=' + platform);
ur.query();
while (ur.next()) {
var user_array = [];
var product_array = user_array.push(ur.u_product.toString());
}
var dee = new GlideRecord("sn_install_base_sold_product");
dee.addEncodedQuery("u_platform=" + platform + "^account=" + accounts);
dee.query();
var arrForSysID = [];
while (dee.next()) {
var prod_array = [];
var arr = prod_array.push(dee.name.toString());
if (JSON.stringify(product_array) == JSON.stringify(arr)) {
gs.log("OUTPUT RESULTS" + dee.sys_id);
arrForSysID.push(dee.getValue('sys_id'));
} else {
gs.log("FALSE RESULT");
}
}
gs.print('Sysid' + arrForSysID);
return 'sys_idIN' + arrForSysID;
},
If the above doesn't work let me know what you are getting in the logs ?
Please mark this comment as Correct Answer/Helpful if it helped you.
Regards,
Swathi Sarang
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎08-28-2024 06:14 AM
Hi @swathisarang98 ,
This is not working.
Thanks,
Sam
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎08-28-2024 10:31 AM
Hi @Samiksha2 ,
In the above you are comparing the jason, try comparing the arrays and also print the product array and the arr and attach the screen shot of the result,
getProduct: function() {
var accounts = current.account;
var platform = current.u_platform;
var subProd = current.getDisplayValue("u_sub_products");
var ur = new GlideRecord("u_sub_product");
var user_array = [];
ur.addEncodedQuery('u_sub_product=' + subProd + '^u_platform=' + platform);
ur.query();
while (ur.next()) {
user_array.push(ur.u_product.toString());
}
var dee = new GlideRecord("sn_install_base_sold_product");
dee.addEncodedQuery("u_platform=" + platform + "^account=" + accounts);
dee.query();
var arrForSysID = [];
var prod_array = [];
while (dee.next()) {
prod_array.push(dee.name.toString());
function areArraysEqual(array1, array2) {
for (var i = 0; i < array2.length; i++) {
if (array1.indexOf(array2[i]) === -1) {
return false;
}
}
return true;
}
var result = areArraysEqual(user_array, prod_array);
if (result == true || result == 'true') {
gs.log("OUTPUT RESULTS" + dee.sys_id);
arrForSysID.push(dee.getValue('sys_id'));
} else {
gs.log("FALSE RESULT");
}
}
gs.info('Product array ' + user_array);
gs.info('arr ' + prod_array);
gs.info('Final sysId ' + arrForSysID);
return 'sys_idIN' + arrForSysID;
},
please share the logs,
Please mark this comment as Correct Answer/Helpful if it helped you.
Regards,
Swathi Sarang