Auto populate the field value on the form
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
3 weeks ago
Hello community !
- SSR will be associated with only one hence for all the standard SSRs product should be populated in Product offering and displayed in the portal.
- For CSR, if the item is associated with single product model, then it should be populated in product offering and displayed in the portal.
- For Bespoke CSR/ Order Guide, if the product is associated and not multiple then populate the product offering and display in the portal else, don't populate the product offering instead add it in the description only. No need to display in portal as well.
SSR & CSR are the catalog item,
There is the script which I have written for the 1 & 2 point it is working fine
but for the 3 point CSR item, one request will be having more than one ritm need to get those item model & product offering & populate in the description of the case
So can anyone help me with the script modification, here is the snippet of code
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
3 weeks ago
Hi @is_12
May you try this code
if (!current.product_offering) {
gs.info("Processing request: " + reqGr.sys_id);
var reqch = new GlideRecord('sc_req_item');
reqch.addEncodedQuery('request=' + reqGr.sys_id + '^cat_item.u_catalog_typeINSSR,CSR');
reqch.query();
var productInfoList = []; // to store all product offerings for description
var singleProductOfferingSysId = null;
while (reqch.next()) {
if (reqch.cat_item.model) {
var modelNumber = reqch.cat_item.model.model_number;
gs.info("Found model: " + modelNumber);
var poGR = new GlideRecord('sn_prd_pm_product_offering');
poGR.addQuery('external_id', modelNumber);
poGR.query();
if (poGR.next()) {
if (modelNumber == poGR.external_id) {
gs.info("Found product offering: " + poGR.sys_id);
productInfoList.push("Model: " + modelNumber + " | Offering: " + poGR.name);
// If only one model, store for direct population
if (!singleProductOfferingSysId) {
singleProductOfferingSysId = poGR.sys_id;
} else {
// If more than one, nullify singleProductOfferingSysId
singleProductOfferingSysId = null;
}
}
}
}
}
if (productInfoList.length == 1 && singleProductOfferingSysId) {
// Only one product offering, populate the field
current.u_prod_offering = singleProductOfferingSysId;
current.update();
} else if (productInfoList.length > 1) {
// Multiple models, append info to description
var descText = "Associated Products:\n" + productInfoList.join("\n");
current.description = (current.description ? current.description + "\n\n" : "") + descText;
current.update();
}
}
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
3 weeks ago
sorry very difficult to visualize what you want without screenshots.
If my response helped please mark it correct and close the thread so that it benefits future readers.
Ankur
✨ Certified Technical Architect || ✨ 9x ServiceNow MVP || ✨ ServiceNow Community Leader
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
3 weeks ago
what screenshot you want, script or the field ?
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
3 weeks ago - last edited 3 weeks ago
try below:
if (!current.product_offering) {
var reqch = new GlideRecord('sc_req_item');
reqch.addEncodedQuery('request=' + reqGr.sys_id + '^cat_item.u_catalog_typeINSSR,CSR');
reqch.query();
var products = [];
var isBespoke = false;
while (reqch.next()) {
// Check if Bespoke CSR
if (reqch.cat_item.u_catalog_type == 'CSR' &&
(reqch.cat_item.type == 'order_guide' || reqch.cat_item.name.includes('bespoke'))) {
isBespoke = true;
}
if (reqch.cat_item.model) {
var modelNum = reqch.cat_item.model.model_number.toString();
if (products.indexOf(modelNum) == -1) {
products.push(modelNum);
}
}
}
// Handle based on count and type
if (isBespoke && products.length > 1) {
// Multiple products - description only
var desc = "Products: " + products.join(', ');
current.description = (current.description || '') + '\n' + desc;
} else if (products.length == 1) {
// Single product - set offering
var poGR = new GlideRecord('sn_prd_pm_product_offering');
poGR.addQuery('external_id', products[0]);
poGR.query();
if (poGR.next()) {
current.u_prod_offering = poGR.sys_id;
}
}
current.update();
}