Workflow Not Updating Workflow State on Related Knowledge Article

Brixio Shaw
Tera Contributor
Hi Team

I am a bit stuck and am hoping someone with a bit more knowledge and experience will see something I don't.

Issue:
The last step of the workflow is to update the workflow_state on the related article to 'published'.

Context:
Flow summary:
- Custom UI Action (Approve) on Custom extended task table (u_knowledge_tasks)
- - UI Action is scripted to triggers workflow if scheduled publish conditions met
- - - Workflow holds timer until scheduled publish date (Workflow Editor) (Date comes through without issue)
- - - - On scheduled publish date Workflow completes and is meant to update task and related article (u_article).
inb4: Was originally implemented by vendor without scheduled published so trying to add it.

UI Action Script:
```javascript
function approveKbTask() {
// var notes = g_form.getValue('work_notes');
// if(notes == ""){
// g_form.setMandatory('work_notes',true);
// g_form.addErrorMessage("Work Notes are mandatory.");
// return false;
// }
gsftSubmit(null, g_form.getFormElement(), 'rml_approve_kb_task');

}
if (typeof window == 'undefined')
closeKnowledgeTask();

function closeKnowledgeTask() {

var isSubmitted = validateAqiChecklist();
if (isSubmitted) {
var gr = new GlideRecord('kb_knowledge');
if (gr.get(current.u_article)) {
var scheduledPublishDate = gr.scheduled_publish_date;
var currentDate = new GlideDateTime();

// Check if the scheduled publish date is in the future
if (scheduledPublishDate && scheduledPublishDate > currentDate) {

var wf = new Workflow();
wf.startFlow(wf.getWorkflowFromName('UKP Scheduled Publish State Change'), current, 'update');
gs.addInfoMessage("The article has been scheduled to publish on the scheduled publish date.");
gr.workflow_state = 'scheduled_publish';
if (gr.update()) {
//current.state = 3;
//current.active = false;
//current.u_code = "Approved";
//current.update();
}
} else {
// Non Scheduled Publish
gr.workflow_state = 'published';
if (gr.update()) {
current.state = 3;
current.active = false;
current.u_code = "Approved";
current.update();
}
}
} else {
gs.addErrorMessage("Please Submit Article Checklist Summary to Approve.");
}
action.setRedirectURL(current);

}

function validateAqiChecklist() {
var chkSum = new GlideRecord("kb_article_checklist_summary");
chkSum.addEncodedQuery("u_kb_task=" + current.sys_id + "^state!=submitted^ORstate=NULL");
chkSum.query();
if (chkSum.next()) {
return false;
}
return true;

}

}
```

Attempted Fixes:
Using 'Set Values' to change the workflow state to published.
Result == Updates task without issue but doesn;t update article.
- Note: Able to dot walk without issue == u_article.workflow_state=published

Using a 'Run Script' with a few different variations:
- Note: Top one references an OOB script include.
```javascript
var kbw = new KBWorkflow();
kbw.publishKnowledge(current.u_article);

/*
var kbKnowledgeGR = current.u_article;

kbKnowledgeGR.workflow_state = "published";
kbKnowledgeGR.retired = "";
kbKnowledgeGR.published = new GlideDate();
*/
/*
var kba = current.u_article;
var kb = kba.kb_knowledge;
var kbw = new KBWorkflow();
kbw.publishKnowledge(kb);
*/
/*
var gr = new GlideRecord('kb_knowledge');
gr.get(current.kb_knowledge);
if (gr.workflow_state == 'scheduled_publish') {
gr.workflow_state = 'published';
gr.update();
}
*/
/*
var kbr = current.u_article;
kbr.workflow_state = 'published';
*/
/*
var gr = new GlideRecord('kb_knowledge');
if (gr.get(current.u_article)) {
gr.workflow_state = 'publish';
}*/
```

Open to any suggestions. Thank you in advance for anyone who gives it a go.

Thanks

Brixio
1 REPLY 1

Brixio Shaw
Tera Contributor
Hi Team,

This has been solved on a ServiceNow support ticket (CS6800206) by an SN Employee (Martin Pan).

Paraphrase of fix:
They tested on the latest OOB Utah instance and found that the Set Values workflow activity is not able to update Dot Walked Record (set the value on the related record) in OOB instance.

According to the documentation https://docs.servicenow.com/bundle/utah-build-workflows/page/administer/workflow-activities/referenc..., the Set Values activity sets values on the current record when the workflow quiesces or ends.

Therefore, it is a current expected behavior that Set Values workflow activity does not support updating Dot Walked Record even if the Set Values workflow activity allow you to dot walk to a field on related record. Set Values workflow activity only support updating current record.

There is a Product Enhancement problem PRB1198233 ("unable to set values on REQ fields using set values activity in RITM workflow") raised for the issue which is pretty much similar to your issue because REQ (sc_request) is the related parent record of the child RITM (sc_req_item) record and Set Values activity in workflow running on RITM is not able to update fields on REQ record. Your issue is that Set Values activity in the workflow "UKP Scheduled Publish State Change" running on child u_knowledge_tasks record is not able to update the field workflow_state on related parent kb_knowledge record. Although the tables are different, but the issue is exactly the same and it is related to the fact that Set Values activity is not able to update field on related record.

The problem PRB1198233 has been marked as "Won't fix" by our DEV team. The DEV team has advised that the reason that we are not going to change this behavior is because there are too many unknown risks around changing that behavior. The DEV team has suggested that there is a easy workaround available for the customer to use.

The workaround has been mentioned in the KB article KB0869482 which was created for PRB1198233.

According to the KB article, the most viable workaround for you would be to utilize a Run Script activity instead of a Set Values activity to update the field workflow_state on the related kb_knowledge record.

You could add a Run Script activity with the following script to the workflow:

var gr = new GlideRecord("kb_knowledge");
gr.get(current.u_article);
gr.workflow_state = "published";
gr.update();

Can confirm that adding the Run Script step after the Set Values resolved the issue.

Thanks

Brixio