The CreatorCon Call for Content is officially open! Get started here.

How to set dynamic data in UI message?

joyceelynn
Tera Contributor

my requirement is to show the message The article <article number> has been retired. when article is retired but currently its showing Knowledge record not found

in the knowledge content widget there is this part in server script

 

else{
data.messages.INSUFFICIENT_PREVILEGES = gs.getMessage("You do not have sufficient privileges to access this knowledge item");
data.messages.RECORD_NOT_FOUND = gs.getMessage("Knowledge record not found");
}

i replace the 'Knowledge record not found' by using system ui messages key = 'Knowledge record not found' and message 'The article {0} has been retired' but {0} should be dynamic showing the current knowledge article number

 

How to do this without modifying the widget server script?

joyceelynn_0-1739763571159.png

 

9 REPLIES 9

Community Alums
Not applicable

Hi @joyceelynn 

Can you verify the following client script:

this script will assist you to inject into the widget's page.

 

function onLoad() {
var message = data.messages.RECORD_NOT_FOUND;
if (message.indexOf('Knowledge record not found') !== -1 && data.article_retired) {
var articleNumber = data.article_number; 
data.messages.RECORD_NOT_FOUND = gs.getMessage('The article {0} has been retired', [articleNumber]);
}
}

Hi @Community Alums I got this error 'The object "gs" should not be used in client scripts.' when trying to create this client script

Community Alums
Not applicable

Hi @joyceelynn 

Use following script to manage the msg.

 

var message = 'The article ' + articleNumber + ' has been retired';

g_form.showFieldMsg('field_name', message, 'error');

 

KrishnaMohan
Giga Sage

Hi @joyceelynn ,

 

I believe we must  have to pass parameter in the method to render dynamically

gs.getMessage('key',parameters);

hence it require to modify server script.

 

Regards,

Krishnamohan