Formatting a Variable in Service Catalog

Mussie
ServiceNow Employee
ServiceNow Employee

Hi Guys,

Does anybody know how to do formatting with a text variable in Service Catalog items? My requirement is as follows:

Users need to insert a particular format:

ABC-12DE34-567-FGHI

The first bit only letters, second bit letters and numbers, third bit only numbers etc. My goal to provide users a nice text box which looks like this and also perform validation at the same time

find_real_file.png

I read in the wiki that I can accomplish this using UI Macros but I couldn't find any useful example that I can use as a guide. Can someone give me some hints?

Regards,

Mussie

1 ACCEPTED SOLUTION

Mussie
ServiceNow Employee
ServiceNow Employee

I was able to do this using regular expressions:



function onChange(control, oldValue, newValue, isLoading) {


    if (isLoading || newValue == '') {


          return;


    }




    //format should be ABC/12DE34/567/FGHI


  var filter = ^([a-zA-Z]{3})\/(\w{6})\/(\d{3})\/([a-zA-Z]{4})$


  if(!filter.test(newValue)){


  alert("Invalid subject code format, it should be in this format - ABC-12DE34-567-FGHI.");


  g_form.setValue('subject_code_string', '');


  }


}



Mussie


View solution in original post

2 REPLIES 2

Mussie
ServiceNow Employee
ServiceNow Employee

I was able to do this using regular expressions:



function onChange(control, oldValue, newValue, isLoading) {


    if (isLoading || newValue == '') {


          return;


    }




    //format should be ABC/12DE34/567/FGHI


  var filter = ^([a-zA-Z]{3})\/(\w{6})\/(\d{3})\/([a-zA-Z]{4})$


  if(!filter.test(newValue)){


  alert("Invalid subject code format, it should be in this format - ABC-12DE34-567-FGHI.");


  g_form.setValue('subject_code_string', '');


  }


}



Mussie


ramnuka
Kilo Contributor

Hi,


I want   name field value does not contains any blank spaces at beginning and ending



example:-


name:   snow(beginning space)


name:snow (ending space)




Thanks,


rambabu