- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎09-28-2016 12:05 AM
Hello,
I would really appreciate help regarding this matter,
We have started to use SN KM as our knowledge tool,
When ever an article is published we have a field like 'Valid to'.We got a requirement like if this Valid date is less than or equal to today,I want this article as retired.
I have wrote an after BR on insert/Update,but its not working.Can some one help on this
var to_date = new GlideDateTime().getDate();
gs.log('today'+to_date);
var valid_date = new GlideDateTime(current.valid_to).getDate();
gs.log('today valid date '+valid_date);
if(to_date <=valid_date) {
gs.log('Today workflow state'+current.workflow_state);
current.workflow_state='retired';
}
Thanks
Saranya
Solved! Go to Solution.
- Labels:
-
Scripting and Coding
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎09-29-2016 12:58 AM
Hi sranya,
try with this in background script, then add it in scheduled job for single record.
var gr = new GlideRecord('kb_knowledge');
gr.addQuery('sys_id','give any valid date less than today kb article sys_id)//remove this line scheduled job
//gr.addQuery('workflow_state', 'published');//add this line when creates scheduled job
gr.query();
while (gr.next()){
var diff = gs.dateDiff(gs.nowDateTime(),gr.valid_to,true)
gs.print(diff);// remove in scheduled job
if (diff) < 0){
gr.workflow_state = 'retire';
gr.setWorkflow(false);
gr.update();
}
}
After run in background script, verify that record if state changes to retire then create scheduled job.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎09-28-2016 01:06 AM
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎09-28-2016 02:09 AM
Hello Mihir,
I have done the same.It not working
Thanks
Saranya
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎09-28-2016 02:15 AM
The business rule is should be of Before type not after.Please recheck this thing.
This script I have provided to you is working perfectly for me.
Thanks,
Mihir
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎09-28-2016 02:20 AM
Hi saranya,
Instead of writing business rule better you can go with scheduled job. It should be better, why because business rule will run when and only insert/update the record only. So if you go with scheduled job set it will run daily/weekly based on your choice.
Just add this line code,
var gr = new GlideRecord('kb_knowledge');
gr.query();
while (gr.next()){
if (gs.dateDiff(gs.nowDateTime(),gr.valid_to,true) < 0){
gr.workflow_state = 'retire';
gr.setWorkflow(false);
gr.update();
}}
or if you want with business rule, Define when to run than just check this condition,
if (gs.dateDiff(gs.nowDateTime(),current.valid_to,true) < 0 ){
current.workflow_state = 'retire';
}