How to use getMessage() in Service Portal?

patricklatella
Mega Sage

I have an onSubmit script that is running a GlideAjax to enforce attachments for a record producer in Service Portal.

I'm getting a warning in the console for the getMessage that synchronous use not supported in Mobile or Service Portal unless message is already cached.  How do I cache the message?  One strange behavior is that the first time the submit button is clicked (and there are no attachments), the alert displays the "key", not the Message.  But then every click on Submit after that correctly displays the Message, but throws Javascript errors.

I'm also getting the "Unhandled exception in GlideAjax" error.  My script is below, anyone see the issue?  Thanks!

find_real_file.png

 

Here's my onSubmit script

function onSubmit() {
var cat_id1 = g_form.getUniqueValue('sysparm_item_guid');
var survey = new GlideAjax('NominationUtil');
survey.addParam('sysparm_name','mandateAttachment');
survey.addParam('sysparm_cart_id',cat_id1);
survey.getXML();/

var answer =survey.getAnswer();
alert('answer is '+answer);//if no attachments, alert says "answer is null"

if(g_form.getValue('u_do_survey_target_employees_in_germany')=='yes'){
if((answer>=0 && answer<3)){
alert(getMessage('DP - survey target employees in germany - yes'));//this is "key" field of the message record
return false;
}
}
if(g_form.getValue('u_do_survey_target_employees_in_germany')=='no'){
if(answer>=0 && answer<2) {
alert(getMessage('DP - survey target employees in germany - no'));//this is "key" field of the message record
return false;
}
else if(answer==2){
return true;
}
else{
alert(getMessage('DP - survey target employees in germany - yes'));//this is "key" field of the message record
return false;
}
}
}

1 ACCEPTED SOLUTION

Omkar Mone
Mega Sage

Hi 

Please find the below thread :- 

https://community.servicenow.com/community?id=community_question&sys_id=b7678b69db1cdbc01dcaf3231f96...

 

Mark correct if i have helped.

 

Regards,

Omkar Mone.

www.dxsherpa.com

View solution in original post

4 REPLIES 4

Omkar Mone
Mega Sage

Hi 

Please find the below thread :- 

https://community.servicenow.com/community?id=community_question&sys_id=b7678b69db1cdbc01dcaf3231f96...

 

Mark correct if i have helped.

 

Regards,

Omkar Mone.

www.dxsherpa.com

Hi Omkar,

thanks for the link...I'm trying to take a solution form it...sounds like I need to add the callback to my alert() script...but the script in that thread won't work in an alert().  Any idea what I need to do to this?  thanks again!

alert(getMessage('DP - survey target employees in germany - yes'), function(msg));//not working

 

Ashutosh Munot1
Kilo Patron
Kilo Patron

HI,


Here you go :

https://community.servicenow.com/community?id=community_question&sys_id=19025feddbdcdbc01dcaf3231f9619a9

 

Thanks,
Ashutosh Munot

patricklatella
Mega Sage

I figured it out...thanks guys!

if(count>=0 && count<2) {
getMessage('DP - survey target employees in germany - no', function(msg){
alert(msg);
});return false;
}