Why isn't URL field keeping the value set by BR?

russellj03
Giga Contributor


I have a URL field in a table that I want to be populated by an onBefore BR that parses a link from the description field.

After the parse and setting the field, I have a log statement that shows the field has the URL value I want, but when I open the record the URL field is blank.

When I manually edit the field (paste in the value), the value stays and works normally, so I know there isn't a problem with the field itself.   Is there something else I need to do after the "current.u_url = url;" line in the BR to make the value stick?

1 ACCEPTED SOLUTION

I figured out the problem, but first my apologies for doing a poor job describing the scenario.



My business rule was calling a script include, which is why the function was written that way, as you pointed out.   The other thing is that the data is coming in via a web service (u_incident), with a transform map transforming the data into the incident table.   But the business rule runs on u_incident, not incident.



The key issue was that when I was setting current.u_url, that was in u_incident, even though the field didn't exist there.   I don't know why I didn't get an error or undefined result when I logged the variable's value.   But once I created the url field in the web service and added it to the transform map, it worked fine with the script the way I originally had it.



Thanks for all of the help!


View solution in original post

8 REPLIES 8

Brad Tilton
ServiceNow Employee
ServiceNow Employee

Could you post the business rule? You also might try the field watcher to see if something else is clearing out the value when you set it via the script.


Does your log statement show that you are getting the correct URL value?



Also in doing this, because it is a URL, be sure to escape the text.


Hi Daniel - yes, the log shows that I am getting the correct value.   As far as escaping, I tried putting the value in single quotes, but that didn't fix it.   I tried setting the field to a static string "abcd1234" and that didn't work.   I also tried the static string "www.abcd1234.com" with escaped the periods, but the syntax checker would not accept that.



If there is another way i should be escaping, please let me know.   Thanks.


I can't post the whole BR without retyping it all, but here is the part that pertains to this problem.   The rest of the BR is working fine, BTW.   Also, this BR fires for tickets received via web service, so client scripts and UI policies don't apply.   Again, the log statement shows the value I want in current.u_url, but it doesn't stick because when I open the ticket the URL field is blank.



...


var url = this.populateURLField();


current.u_url = url;


gs.log("u_url = " + current.u_url);


...



populateURLField : function() {


  var urlRegex = /(https?:\/\/[^s]+)/g;


  var urls = current.description.match(urlRegex);


  return urls[0];


}