Join the #BuildWithBuildAgent Challenge! Get recognized, earn exclusive swag, and inspire the ServiceNow Community with what you can build using Build Agent.  Join the Challenge.

How to replace string value in middle of the particular value

Jay N
Tera Contributor

Hi Experts,

We have a catalog item with one of the variable value, when user input particular value (i.e, https://dev.company.com/Enterprise-company-Org/PRJ-project/_build?definitionId=4841), as user inputs and changes to other field we need to populate with above value with additional changes(like https://dev.company.com/Enterprise-company-Org/PRJ-project/_apis/pipelines/4841/runs?api-version=6.0-preview.1).

"_build?definitionId=" should be replaced with "_apis/pipelines/" at the end append with "/runs?api-version=6.0-preview.1"

May i request experts inputs for this requirement.

find_real_file.png

Thanks, Jay

1 ACCEPTED SOLUTION

Jaspal Singh
Mega Patron
Mega Patron

Hi Jay,

You can use below logic in client script

var str = g_form.getValue('field_name');//replace field name with text where user enters

var res = str.replace(/_build\?definitionId/g, "_apis/pipelines/");

var finalres=res +'/runs?api-version=6.0-preview.1';

//finalres can then be used to set value

View solution in original post

1 REPLY 1

Jaspal Singh
Mega Patron
Mega Patron

Hi Jay,

You can use below logic in client script

var str = g_form.getValue('field_name');//replace field name with text where user enters

var res = str.replace(/_build\?definitionId/g, "_apis/pipelines/");

var finalres=res +'/runs?api-version=6.0-preview.1';

//finalres can then be used to set value