- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
08-04-2016 12:59 AM
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
Please suggest
Regards,
Sadashiv Das
Solved! Go to Solution.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
08-04-2016 01:40 AM
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);
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
08-04-2016 02:43 AM
Many thanks to Zic,
Sorry for confusion .I am explaining again . we have custom field called State and we have written ACL .After upgrade to Helsinki new field introduced called Status(state)is contradicting our ACL(which having OBT functionality on server side ) .Our requirement to 200 project before upgrade to Helsinki . so we have to set the filled values of State to >>>>>new OBT field Staus(state) .
We have to write server side script to achive this .
Please suggest .
Regards,
Sadashiva
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
08-04-2016 03:10 AM
In that case, you would need to use "Fix script"
And on this this script, I would query the necessary projects using GlideRecord and on a "while loop", I would update the state.
One strong advice, in your query, use "setLimit" method so you would be able to make tests with few projects before saying "my script is good enough, I can do a final test to make sure everything is working fine".
Please make a try and come back with your proposition
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
03-29-2017 03:32 AM
Do this script updates the expected value old records also?
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
08-04-2016 03:26 AM
Das,
David is right, a fix script will do the work and do not forget his strong advice.
I don't know which table you are working on, here again a sample of the script that could be used (I am not the expert, David feel free to correct my script please )
UpdateStatusfromState(); approval.setLimit(5); // Sets the limit for how many records are in the GlideRecord. approval.update(); }} |
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
08-04-2016 04:29 AM
David,
Thank you for your feedbacks
The sample of the Business rules proved is actually for Geneva version. However the fix script was made on Eureka version (and it is working).
I agree with you the role of the community isn't to undermine training, it's complementary. I just meant that we should assist them more and it is important for them to better understand the platform.