Client script to display a message when the no_order_now is true

stprsbk
Giga Guru

I have a request to display a message when a catalog item is active, but the no_order_now box is checked (true).  Reading through numerous post I thought the following should work, but I have been unable to have the message display using the following client script.  Any suggestions?

function onLoad() {
   var noOrder = g_form.getValue('no_order_now');
   if (noOrder == 'true') {
          g_form.addErrorMessage('Registration is currently closed. Please review the program dates below for the next date to register.');
    }
}
1 ACCEPTED SOLUTION

stprsbk
Giga Guru

Since the client script doesn't have direct access to the No Order Now fields, using the following AJAX script was able to get this functioning.

function onLoad() {

var ga = new GlideAjax("USUCatalogUtilsAJAX");
ga.addParam("sysparm_name", "isNoOrder");
ga.addParam("sysparm_item_sys_id", "76e5e2b42c58c200e3b1ebb13bc3ad8c"); //catalog item sys_id
ga.getXMLAnswer(function(answer) {
if(answer == "true") {
g_form.addErrorMessage('Your message is place here.');
}
});
}

View solution in original post

3 REPLIES 3

AshishKM
Kilo Patron
Kilo Patron

Hi @stprsbk , 

Please check if UI Type = All 

AshishKM_0-1722637940929.png

Result : Message is displaying but it will disappear within few seconds.

AshishKM_1-1722638016532.png

 

Note: If this is not something you are looking for, then please explain the business case in details. 

 

-Thanks,

AshishKM

 

 

 

 


Please mark this response as correct and helpful if it helps you can mark more that one reply as accepted solution

Hello @AshishKM,

Thank you for your reply.  The UI Type is set to All.  

The business case: we have a catalog item individuals use to register for an event.  The catalog item is only open during specified times of the year.  Previously we had marked the catalog item as inactive, but this confused a few users who were looking for the catalog item.  We were asked if we could have it active all year long but only display the Submit button when registration is open.  This part is working.  But now they want a message with a brief explanation (error message) displayed when the submit button is unavailable.  Since we use the no_order_now field to display or hide the Submit button, we are hoping we can use this same field to display an error message to users when the field is 'true'.  I have attached our current script, which looks the same as what you had posted, but we cannot get ours to function.

stprsbk
Giga Guru

Since the client script doesn't have direct access to the No Order Now fields, using the following AJAX script was able to get this functioning.

function onLoad() {

var ga = new GlideAjax("USUCatalogUtilsAJAX");
ga.addParam("sysparm_name", "isNoOrder");
ga.addParam("sysparm_item_sys_id", "76e5e2b42c58c200e3b1ebb13bc3ad8c"); //catalog item sys_id
ga.getXMLAnswer(function(answer) {
if(answer == "true") {
g_form.addErrorMessage('Your message is place here.');
}
});
}