- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
11-12-2023 02:43 AM - edited 11-12-2023 02:45 AM
Dear Team,
I am working on a requirement where there is a catalog item 'MS Office Management Request', once the variable is filled and clicked on the 'Submit' request, then a second checkout box 'Order Confirmation' pops up and here when choosing 'Request for', then need to check if the selected 'Request for' user profile is created less than 72 hours or not, if Yes, profile created less than 72Hrs then pops up an error message 'The selected user profile is created less than 72 Hours, so please wait until all licenses assigned to the user' and clears the 'Request for' field.
and If the selected user profile was created more than 72 hours ago, then allow it to be filled.
I used the below URL provided solution steps to make the 'Order Confirmation' box's field 'Request for' by default 'None' and it worked-
Requesting further help to get my requirement fulfilled.
Thanks in advance
Thanks
Solved! Go to Solution.

- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
11-13-2023 03:25 AM - edited 11-13-2023 03:26 AM
ok good, this just got a lot easier.
You will need to create a client callable script include to be called by glideAjax:
var checkUserCreation = Class.create();
checkUserCreation.prototype = Object.extendsObject(AbstractAjaxProcessor, {
checkCreation:function(){
var sysid = this.getParameter('user_sys_id');
var user = new GlideRecord('sys_user');
user.get(sysid);
var cDate = user.sys_created_on;
var now = new GlideDateTime();
var dur = gs.dateDiff(cDate,now);
var diff = new GlideDuration(dur);
diff = diff.getNumericValue()/1000/60/60; // calculating the total duration in hours
if (diff < 72){
return true;
}
else {
return false;
}
}
});
then create an onChange client script for your catalog item that calls the ajax and checks the result. If user is created less than 72 hours ago, it will trigger an alert and clear the field value.
function onChange(control, oldValue, newValue, isLoading) {
if (isLoading || newValue == '') {
return;
}
var ajax = new GlideAjax('checkUserCreation');
ajax.addParam('sysparm_name','checkCreation'); //time comparison function in ajax script
ajax.addParam('user_sys_id', newValue); //pass in selected user value
ajax.getXML(myCallback);
function myCallback(response){
var answer = response.responseXML.documentElement.getAttribute("answer"); //dig out answer from ajax
if (answer == 'true'){
alert("The selected user profile is created less than 72 Hours, so please wait until all licenses assigned to the user")
g_form.clearValue('u_requested_for'); //change field name to the name of your variable
}
}
}
Please mark my reply as answer or helpful if this resolves your issue.

- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
11-12-2023 09:26 PM - edited 11-12-2023 09:27 PM
Looks like you're using 2 step cart on service portal, which means you are going to need to get stuck into the service portal widgets
you will need to clone the Catalog Checkout (sc-checkout) widget to include your logic that checks the user's creation date and does it's thing. You'll need to do some funky stuff but it should be possible with enough swearing.
then clone SC Catalog Item (widget-sc-cat-item-v2) widget and modify it to call your new Catalog Checkout widget instead of the oob one.
then update your portal design to use your new cloned widget instead of the oob one.
OR
you can ditch the 2 step cart and enjoy a much less stressful solution involving client scripts.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
11-12-2023 09:48 PM
Hi @Kai Tingey Sir thanks for your clear advise, second option is much more reliable than first one.
I have created a new Variable 'Requested for' on catalog item itself Now, requesting to please help with onchange client script which checks the criteria (if selected user profile is created less than 72 hours then pops up an error message 'The selected user profile is created less than 72 Hours, so please wait until all licenses assigned to the user' and clears the 'Requested for' field.
and If the selected user profile was created more than 72 hours ago, then allow it to be filled.
Once the selected user in requested for fits the criteria then at the time of Submit the order, the 'Request for' field on 'Order Confirmation' checkout box should contains that same name.
Thank you and please help sir.

- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
11-13-2023 03:25 AM - edited 11-13-2023 03:26 AM
ok good, this just got a lot easier.
You will need to create a client callable script include to be called by glideAjax:
var checkUserCreation = Class.create();
checkUserCreation.prototype = Object.extendsObject(AbstractAjaxProcessor, {
checkCreation:function(){
var sysid = this.getParameter('user_sys_id');
var user = new GlideRecord('sys_user');
user.get(sysid);
var cDate = user.sys_created_on;
var now = new GlideDateTime();
var dur = gs.dateDiff(cDate,now);
var diff = new GlideDuration(dur);
diff = diff.getNumericValue()/1000/60/60; // calculating the total duration in hours
if (diff < 72){
return true;
}
else {
return false;
}
}
});
then create an onChange client script for your catalog item that calls the ajax and checks the result. If user is created less than 72 hours ago, it will trigger an alert and clear the field value.
function onChange(control, oldValue, newValue, isLoading) {
if (isLoading || newValue == '') {
return;
}
var ajax = new GlideAjax('checkUserCreation');
ajax.addParam('sysparm_name','checkCreation'); //time comparison function in ajax script
ajax.addParam('user_sys_id', newValue); //pass in selected user value
ajax.getXML(myCallback);
function myCallback(response){
var answer = response.responseXML.documentElement.getAttribute("answer"); //dig out answer from ajax
if (answer == 'true'){
alert("The selected user profile is created less than 72 Hours, so please wait until all licenses assigned to the user")
g_form.clearValue('u_requested_for'); //change field name to the name of your variable
}
}
}
Please mark my reply as answer or helpful if this resolves your issue.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
11-13-2023 04:29 AM
Thanks @Kai Tingey Sir, This is working as expected
alert("The selected user profile is created less than 72 Hours, so please wait until all licenses assigned to the user");
Only ';' missing on the above line of Onchange CS.
Marking your answer as correct and helpful, thank you once again 🙂