- 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 05:51 AM
That is a really user-mocking way to do it.
Like you let the user do some work, then at the very end you tell them they just wasted all that time and effort.
Why not show that message right after the Requested for user is selected (with an onChange Catalog Client Script)?
That way users will know from the get-go that there is no point in wasting their time.
As for the requirement itself, while it is possible, you would have break most best-practices there are - as something like that is not supported OOB.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
11-12-2023 09:54 PM
Hi Sir @-O- @ 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 12:13 AM
You're welcome.
When you say "created 72 Hours ago", what do you mean exactly?
Is it when created in ServiceNow, or somewhere else?
As for the implementation of the check, do you know how to user GlideAjax?
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
11-13-2023 12:24 AM
@-O- Sir, I mean user profile in ServiceNow created within last 72hours if yes then pops up an error message and clears the value, else profile created more than 72 hours ago then allowed such users selection.
I know about GlideAjax but unable to get utilize here. If possible please help with script so that It can be achieved.
Thanks