Update SKU and related document when using Workflow with versioning and check-in/check-out.

When you are using Workflow (WF) with versioning along with check-in/check-out functionality, product documents are checked-in so they cannot be edited.  In this case it’s necessary to follow the WF process and update not just the SKU, but also the related document.
Here is the example of updating a specific SKU (SKUID = 236) price via API:

TreeProvider tree = new TreeProvider(CMSContext.CurrentUser); NodeSelectionParameters nsp = new NodeSelectionParameters(); nsp.Where = "NodeSKUID = 236"; CMS.DocumentEngine.TreeNode node = tree.SelectSingleNode(nsp); if (node != null) { WorkflowManager workflowmanager = WorkflowManager.GetInstance(tree); VersionManager versionmanager = VersionManager.GetInstance(tree); WorkflowInfo workflow = workflowmanager.GetNodeWorkflow(node); if (workflow != null) { // Check if the workflow uses check-in/check-out functionality if (workflow.UseCheckInCheckOut(CMSContext.CurrentSiteName)) { if (!node.IsCheckedOut) versionmanager.CheckOut(node); if (node.IsCheckedOut) { SKUInfo updateProduct = SKUInfoProvider.GetSKUInfo(236); // Update the product - SKU updateProduct.SKUAvailableItems = 99; SKUInfoProvider.SetSKUInfo(updateProduct); // Update a related document node.SetValue("SKUAvailableItems", updateProduct.SKUAvailableItems); DocumentHelper.UpdateDocument(node, tree); versionmanager.CheckIn(node, null, null); } } } }

See also: API Examples of Managing documents with WF

Applies to: Kentico CMS 7.x
Share this article on   LinkedIn

Martin Danko

Let me guide you on your journey of success. I will show you how to optimize your content production with Kentico Draft. Check out www.kenticocloud.com