How run One time script ?
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎06-30-2013 11:52 PM
Hello,
I have a question please, how to run One time script to replace one value on the incident form with another value ?
What is the best way?
I have example script below. I need replace existing value with new value . Below is only example where i need to start learn my knowledge and test it...
Im not experienced yet, but here is my proposal how to manage it.
Create client script and schedule it to run it once ?
or
Just create script in schedule job and run it once ?
Please help me to learn hot to do it.
Thank you for your help.
Here is a script example:
var inc = new GlideRecord('incident');
// Change all Open(1) incidents to Active(2)
inc.addQuery('incident_state', 1);
inc.query();
var inc = new GlideRecord('incident');
// Change all Open(1) incidents to Active(2)
inc.addQuery('incident_state', 1);
inc.query();
while (inc.next()) {
inc.autoSysFields(false); // Do not update sys_updated_on, sys_updated_by, and sys_mod_count
inc.setWorkflow(false); // Do not run any other business rules
inc.setValue('incident_state', 2);
inc.update();
}
Petr
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎07-01-2013 12:58 AM
If it is a one time script you need to run then make use of "Scripts - Background".
See http://wiki.servicenow.com/index.php?title=High_Security_Settings#Elevated_Privilege
Your current script should run fine in this.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎07-01-2013 03:41 AM
Thanks a lot, it work perfectly.
I guess your first name is Laurens. Correct me if im wrong please.
Laurens, please
I have one more question . Its related to this topic. { please let me know also if I shall better close this and open new topic to the below.}
What are the key words to move the value from one field to Another field on the same form ?
For example I have Field 'A' and value 123 and I want by this one time script to move that value from Field 'A' to field 'B'.
I have something like below done where 'u_company_mill_code_fin' is choice list and 'u_iil' is reference field.
I guess i shall specify more variable in the one time script?
Please tell me for which key words I should look for on wiky to find correct material and achieve to copy field value A to another field B.
The value which exist in field A ( one table ) , exist in database for Field B ( different table ).
Thank you for your time
Petr
var acc = new GlideRecord('u_accounting');
acc.addQuery('u_company_mill_code_fin','FI_01');
acc.addQuery('short_description','123456789abc');
acc.query();
while (acc.next()) {
acc.autoSysFields(true); // Do not update sys_updated_on, sys_updated_by, and sys_mod_count
acc.setWorkflow(false); // Do not run any other business rules
acc.setValue('u_iil',acc);
acc.update();
}
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎07-01-2013 04:40 AM
Petr,
Your record variable is "acc".
So before the acc.update() write some like
acc.field1 = acc.field2
which copies field2 to field1.
The above assumes that the field type of field1 and field2 is the same
Regards,
Laurens (firstname 🙂 )
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎07-01-2013 05:30 AM
This work exactly as you described. Thank you.
I have end of my script like below.
acc.u_iil = acc.u_company_mill_code_fin;
acc.update();
}
Value from u_company_mill_code_fin; has been copy to field u_iil.
Perfect.
But why it does not work when the fields are different types even the exactly same value exist on both tables.
String field value have to be moved to Reference field. I have tried and it really does not work as you mentioned.
I understand that fields are different types, but exactly same values exist on tables between them.
Have you any advice to this ?
Petr