How to write server side script to update the field values from one field to another field in Project module ?

Sadashiva Das
Tera Expert

How to write server side script to update the field values from one field   to another field     in Project   module ?

In Project we have field called State and Status.

My question is how to set the field value on State ( current value of state )will update or stet to   to Status field values in Project

Screen shot attached for reference

find_real_file.png

Please suggest

Regards,

Sadashiv Das

1 ACCEPTED SOLUTION

zica
Giga Guru

Das,



if you create a business rule, it will run on the server side (In opposite of client script that runs on client side)


This following article explains the difference between the scripts into servicenow, it will help you to get a broader perspective of how and where to script in Servicenow : Differences Among Scripts - ServiceNow Wiki



To answer to your question, you can create a Before business rules.


Put the table name on which the Business rule should operate. Do not forget to check also the "advanced" checkbox (as you will need to script a little bit)


Under the filter condition, you can put something similar to this condition : State changes


Under advanced tab, You have to write your script. I only provide you the sample of the script that you can use :



(function executeRule(current, previous /*null when async*/) {


     


      if (current.state == '3')   { // make sure to put the value and not the label


              current.u_status = "ValueOfTheStateOfYourChoice1";


      }



      if (current.state == '4') {


              current.u_status = "ValueOfTheStateOfYourChoice2";


      }



})(current, previous);


View solution in original post

18 REPLIES 18

david_legrand
Kilo Sage

Hi,



On this one, I won't give you the exact answer as it's something every ServiceNow developer should learn.


So please try to create a Business Rule "before"


Create a business rule



If you have troubles, feel free to continue the discussion


Best regards,


I should answer him or not, in dilemma after you said that he should learn .


It's always a dilemma . I do believe we (people who knows) shouldn't give straight away the answers when the question is about "knowledge every admin have to know" but instead ask the person to do and we help if they have issues.


And when the question is more tricky, we can give the straight answer because of the trickiness.



I would like it to be a global policy on the Community as we want to empower new admins and not only show that we know


But what do you think?


David you are very correct even I feel people should look/ search and try to find themselves first and then post here when its not feasible at all.


Even I don't want to give exact answers at least for very simple questions. But ya then we think to help people in every way we can...


Lets c how it goes here..



@ Sadashiva : Let us know if you are able to find the answer or not