Example 2 Restrict Status Change if Affected Items Have No Attachment

You can write a Groovy script that restricts the status change of a change order from Open to Approval if the affected items don't have attachment.

In the change exit criteria for the Open to Approval phase, the script should check if the affected objects if the affected items has atleast one attachment. If there are no attachments, it should restrict the promotion to approval.

Here are the configuration steps:
  1. Create a web service.
    1. Web service: GetAffectedItem

      URL: https://hostname/fscmRestApi/resources/11.13.18.05/productChangeOrders/##changeId##/child/AffectedObject
    2. Web service: GetAIAttachments

      URL: https://hostname/fscmRestApi/resources/11.13.18.05/productChangeOrders/##changeId##/child/AffectedObject/##itemId##/child/AffectedItemAttachment

  2. Create a global function in Application Composer.
    Note: This global function is provided only as reference.
    • Trigger: Item Rules
    • Object: Change Order
    • Tab: Affected Item -> Attachment
    • Application Composer Navigation: Change Order ->Global Function Criteria at Open status
    • Function:
      def itemId = ""
      def rtrnVal
        changeId = String.valueOf(changeId)
        println(changeId)
        def aitems = adf.webServices.GetAffectedItem.GET(changeId)
        def ailnk = aitems["items"]
        for(affectedItem in ailnk)
        {
          println("In the loop")
          def links = affectedItem["links"]
          for(lnk in links)
          {
         if(lnk["rel"].toString() =="self" && lnk["name"].toString()=="AffectedObject")
          {
            println(lnk["href"])
       itemId = String.valueOf(lnk["href"].toString().replace("https://hostname/fscmRestApi/resources/11.13.18.05/productChangeOrders/"+changeId+"/child/AffectedObject/",""))
          println(itemId)
          }
          println(itemId)
          def attResult = adf.webServices.GetAIAttachments.GET(changeId,itemId)
            def attachments = attResult["items"]
            println(attachments["count"])
            if(attachments!="[]")
            {
              rtrnVal = false
              println("No attachments")
              println(rtrnVal)
            }
        }
        }
      return rtrnVal
      

  3. Set up Item Rule: InvokeGlobalFunction("hasAttachment", [ChangeHeader].[Change Header Main].[Change ID])

    Here's how you define the rule in Edit Rule page

    This image displays function for items with attachments
  4. Define the change order entry criteria in the Workflow tab of the Edit Change Order Type page.

    Add the VS Validate Attachment as the entry criteria for the approval status.

    This image shows the change order with entry and exit criteria