To make 'Request for' field in Order confirmation box 'Read only' for a specific catalog item only
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
11-14-2023 09:29 AM
Team,
I need help with customization to the Server Script in the Cloned Catalog Checkout Widget, so that the 'Request for' field on the Confirmation checkout box will be Read only for a specific catalog item only rest for any other catalog item it should be Editable.
sys_id for that specific catalog item is- sys_id=e21b6e8f971c7110e6e3bb5ef053af7d
for which the Request for field should be Read only
The server script is-
(function() {
var localInput = input; //to safeguard pullution of "input" via BR or other scripts
var engagementChannelOptions = { //extracting here to safeguard pollution of 'options' via other scripts
native_mobile : options.native_mobile,
isServiceWorkspace : options.isServiceWorkspace
};
data.engagement_channel = new global.GlobalServiceCatalogUtil().getEngagementChannel(engagementChannelOptions);
data.referrer = options.referrer;
data.action = options.action;
if (data.action)
data.item = options.item;
else
data.action = 'checkout';
if (localInput && localInput.action == "from_attachment")
return;
else if (localInput && localInput.action === 'log_request') {
$sp.logStat('Order Now Request', localInput.itemDetails.sys_class_name, localInput.itemDetails.sys_id, localInput.itemDetails.name, $sp.getPortalRecord().getUniqueValue());
$sp.logStat('Cat Item Request', localInput.itemDetails.sys_class_name, localInput.itemDetails.sys_id, localInput.itemDetails.name, $sp.getPortalRecord().getUniqueValue());
return ;
}
var cartName = '';
if (localInput)
cartName = localInput.cart.name;
else if (options.cart)
cartName = options.cart.name;
addInstrumentationData();
var m = data.msgs = {};
m.dialogTitle = gs.getMessage("Delete Attachment");
m.dialogMessage = gs.getMessage("Are you sure?");
m.dialogOK = gs.getMessage("OK");
m.dialogCancel = gs.getMessage("Cancel");
m.renameSuccessMsg = gs.getMessage("Attachment renamed successfully");
m.deleteSuccessMsg = gs.getMessage("Attachment deleted successfully");
m.delete_attachment = gs.getMessage("Delete Attachment?");
m.requestSubmitted = gs.getMessage("Thank you, your request has been submitted.");
m.checkingOutMsg = gs.getMessage("Submitting...");
if (data.item.request_method == "request") {
m.checkOutMsg = gs.getMessage("Request");
m.checkoutPopupTitle = gs.getMessage("Request Confirmation");
} else {
m.checkOutMsg = gs.getMessage("Checkout");
m.checkoutPopupTitle = gs.getMessage("Order Confirmation");
}
data.isMEE = options.native_mobile == 'true';
data.sys_properties = {
mobileNativeColor: gs.getProperty("glide.sc.mobile.primary_color", "#1f8476"),
isPolaris: gs.getProperty("glide.ui.polaris.experience", "false")
};
data.maxAttachmentSize = parseInt(gs.getProperty("com.glide.attachment.max_size", 1024));
if (isNaN(data.maxAttachmentSize))
data.maxAttachmentSize = 24;
m.largeAttachmentMsg = gs.getMessage("Attached files must be smaller than {0} - please try again", "" + data.maxAttachmentSize + "MB");
var cartJS;
if (data.action !== 'order_now') {
cartJS = new sn_sc.CartJS(cartName, '' + gs.getUser().getID());
if (localInput && localInput.action === "change_shipping_info") {
cartJS.setSpecialInstructions(localInput.special_instructions);
cartJS.setRequestedFor(localInput.requestedFor);
cartJS.setDeliveryAddress(localInput.deliverTo);
}
}
if (localInput && localInput.action == 'order_guide') {
var guideJS = new sn_sc.OrderGuide('' + cartName);
cartJS = new sn_sc.CartJS('' + cartName);
for(var i = 0; i < localInput.item.items.length; i++) {
guideJS.navigateFromMap(localInput.item.items[i]);
}
cartJS.activateGuide();
cartJS.setRequestedFor(localInput.requested_for);
cartJS.setDeliveryAddress(localInput.delivery_address);
cartJS.setSpecialInstructions(localInput.special_instructions);
cartJS.setParentParams(localInput.parentParams);
cartJS.setEngagementChannel(localInput.engagement_channel);
cartJS.setReferrer(localInput.referrer);
var request = cartJS.checkoutGuide();
data.result = {sys_id: request.request_id, number: request.request_number || request.number, table: request.table || 'sc_request'};
var portalId = $sp.getPortalRecord().getUniqueValue();
$sp.logStat('Order Now Request', localInput.item.sys_class_name, localInput.item.sys_id, localInput.item.name, portalId);
$sp.logStat('Cat Item Request', localInput.item.sys_class_name, localInput.item.sys_id, localInput.item.name, portalId);
return;
}
if (localInput && localInput.action === 'checkout') {
cartJS.setEngagementChannel(localInput.engagement_channel);
checkoutCart(cartJS);
return;
}
if (data.action !== 'order_now')
data.cart = cartJS.getCartDetails(false);
else {
var requested_for = {
user_id : gs.getUser().getID(),
user_name: gs.getUser().getDisplayName()
};
data.cart = {
name: cartName,
sys_id: gs.generateGUID(),
requested_for: requested_for.user_id,
//Custom//requested_for: '',
requested_for_display_name: requested_for.user_name,
//custom//requested_for_display_name: '',
delivery_address: sn_sc.CartJS.getRequestedForAddress(requested_for.user_id)
//custom//delivery_address: sn_sc.CartJS.getRequestedForAddress(gs.getUser().getID())
};
}
if (options && options.parentParams) { //if parent is passed
data.parentParams = options.parentParams;
}
if (options && options.requested_for && options.requested_for.id) { //If Passed via options
data.cart.requested_for = options.requested_for.id;
data.cart.requested_for_display_name = options.requested_for.displayValue;
data.cart.delivery_address = sn_sc.CartJS.getRequestedForAddress(options.requested_for.id);
}
if (data.request_for) { //if value is changed by user
var user = GlideUser.getUserByID(data.request_for);
if (user.exists()) {
data.cart.requested_for = data.request_for;
data.cart.requested_for_display_name = user.getDisplayName();
data.cart.delivery_address = sn_sc.CartJS.getRequestedForAddress(data.request_for);
}
}
data.disable_req_for = sn_sc.CartJS.canViewRF();
setRequestedForCols(data);
data.reqForQuery = gs.getProperty("glide.sc.request_for.query");
})();
function setRequestedForCols(data) {
var reqForDispCols = gs.getProperty("glide.sc.request_for.columns");
if (JSUtil.notNil(reqForDispCols)) {
data.reqForDispCol = "name";
data.reqForDispCols = reqForDispCols.replace(/;/g, ",");
data.reqForSearchCols = data.reqForDispCol + "," + data.reqForDispCols;
}
else {
var displayCol = GlideTableDescriptor.get("sys_user").getDisplayName();
data.reqForDispCol = displayCol || "name";
data.reqForSearchCols = data.reqForDispCol;
var refAcCols = GlideTableDescriptor.get("sys_user").getED().getAttribute("ref_ac_columns");
if(JSUtil.notNil(refAcCols))
data.reqForDispCols = (refAcCols + "").replace(/;/g, ",");
var refAcSearch = GlideTableDescriptor.get("sys_user").getED().getAttribute("ref_ac_columns_search");
if(JSUtil.notNil(data.reqForDispCols) && JSUtil.notNil(refAcSearch) && refAcSearch == "true")
data.reqForSearchCols += "," + data.reqForDispCols;
}
}
function checkoutCart(cart) {
try {
var cartItemGr = cart.getCartItems();
data.numberOfCartItems = cartItemGr.getRowCount();
var requestedCatItems = new global.GlobalServiceCatalogUtil().findCatItemsForSpLogs(cartItemGr);
var request = cart.checkoutCart(true);
data.result = {
sys_id: request.request_id,
number: request.request_number,
table: 'sc_request',
universal_request: request.universal_request
};
var portalId = $sp.getPortalRecord().getUniqueValue();
$sp.logStat('Checkout Request', 'sc_request', request.request_id, request.request_number, portalId);
new global.GlobalServiceCatalogUtil().logRequestedCatItems(requestedCatItems, portalId);
} catch(e) {
var catalogExceptionUtils = new CatalogExceptionUtils();
if(catalogExceptionUtils.isCartException(e))
gs.addErrorMessage(e.getMessage());
data.numberOfCartItems = 0;
}
}
function addInstrumentationData() {
if (input && input.action == 'change_shipping_info')
return;
if (data.action == 'order_now') {
var catSysId = data.item.sys_id;
var gr = new GlideRecord('sc_cat_item');
if (gr.get(catSysId))
data.item.title = gr.getValue('name');
} else if (input && input.cart && data.action == 'checkout') {
var cartData = [];
var _data;
var cartSysId = input.cart.sys_id;
var grCart = new GlideRecord('sc_cart_item');
grCart.query("cart", cartSysId);
while(grCart.next()){
_data = {};
var gr2 = new GlideRecord('sc_cat_item');
if (gr2.get(grCart.getValue("cat_item"))) {
_data.sys_id = gr2.getValue('sys_id');
_data.title = gr2.getValue('name');
_data.cartID = cartSysId;
cartData.push(_data);
}
}
data.cartData = cartData;
}
}
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
11-14-2023 10:42 AM
@Mark Roethof Sir, any help on this please.

- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
11-14-2023 11:23 PM - edited 11-14-2023 11:23 PM
what you are asking for isn't easy. Setting the field read only is easy via HTML but it's a global change. To specify it for a particular catalog item you will want to find a way to write an if statement that checks if the catalog item is a specific sys_id. You cant do that in the HTML (that i know of, very happy to learn otherwise).
you might be better off trying to find the submit function, and altering that to check if current catalog item = (sys id of the one you want) and requested for user is (who you want) - if condition matches then form submits, otherwise prevent submission.
seems like a lot of hassle.
what is the requirement of the form?
who are you trying to limit access to? Currently it appears your code populates the requested for with the current logged in user. If that is correct and you set it to read only, it will have the effect of locking it to be the current logged in user always, which will be counter intuitive to having a user selectable 'requested for' on the catalog item itself.
Perhaps have a read of this thread, it seems like their requirement is somewhat similar to yours. It might give you a different path.