Can we pass message key to spModal.confirm() in a client script while showing the Modal Popup?

Subhashree3
Giga Contributor

Hi All,

Is there any way to pass the message key to the spModal.confirm() function in a client script while implementing a modal popup?

PFB code where currently I am passing the message which needs to be replaced with the message key in the client script in order to show the Modal Popup.

if(val && newValue!=oldValue){
if (typeof spModal != 'undefined')
{
spModal.confirm("Can you confirm or deny this?").then(function(confirmed) {   //Need to pass the Message key here
//spModal.confirm(getMessage('privateAttachmentCheck')).then(function(confirmed) {
flag =true;
});
}
if (flag != true){
return false;
}

}

Thank You

2 REPLIES 2

Bhawanjit Sing2
Mega Guru

getMessage() function can be accessed using gs (gs.getMessage('value')). So gs is only available in server side script so while the widget loads you have to store your value in the server side first and then you can use it any where.

// Server script
data.myMessage = gs.getMessage('privateAttachmentCheck');

//Client script
spModal.confirm(data.myMessage).then(function(response){
//your logic
});

 

Please mark the solution helpful if it works for you.

SatheeshKumar
Kilo Sage

yes you can translate the value like below:

spModal.confirm("${Can you confirm or deny this?}").then(function(confirmed) {

 

the above will pull data pull message from messages table for your key value.

 

for more details check the below link:

https://docs.servicenow.com/bundle/london-servicenow-platform/page/build/service-portal/concept/c_WidgetLocalization.html

 

-satheesh