We've updated the ServiceNow Community Code of Conduct, adding guidelines around AI usage, professionalism, and content violations. Read more

The variable should contain 'example' as an prefix

Archana23
Tera Contributor

The variable should contain 'example' as an prefix. how to achieve this

4 REPLIES 4

Damini Sheth
Tera Contributor

Hi,

can you explain your use case a little bit more, so we can try a solution?

 

Thanks,

Damini Sheth

I should create a variable named 'account' with free text and it should contain the word 'example' as an prefix.

Hi, try to use the onChange client script with the below code: 

function addPrefix(varName, strValue) {
//varName is the variable name
//strValue is the entered value of the Single Line Text variable
g_form.setValue(varName, xStr);
return;
}
function onChange(control, oldValue, newValue, isLoading) {
if (isLoading || newValue == '') {
return;
}
addPrefix('example', newValue);
return;
}
 

If my answer solved your issue, please mark my answer as Correct & 👍Helpful based on the Impact

 

Thanks,
Damini Sheth

 

Not applicable

Hi @Archana23 ,

You can create Client script

a few examples:

onLoad client script: set prefix to variable


onChange client script: concatenate a string with prefixes when data is entered

onSubmit client script: concatenate a string with prefixes when form in submited

Also, you can refer to this solution and replace it with "Example" :https://www.servicenow.com/community/developer-forum/how-to-add-a-symbol-as-prefix-in-a-variable/m-p...