Example 1 Restrict Status Change if Affected Items Have No AML

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 AML.

Use Case: In the change exit criteria for the Open to Approval phase, the script should check if the affected objects have at least one AML (approved manufacturers list). If there’s no AML, it should restrict the promotion to approval.

  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: GetAIAML

      URL: https://hostname/productChangeOrders/##changeId##/child/AffectedObject/##itemId##/child/AffectedItemAML

  2. Create a global function - hasAML:
    Note: This global function is provided only as a reference.
    • Trigger: Item Rules
    • Object Change Order
    • Tab: Affected Item -> AML
    • Application Composer Navigation: Change Order -> Global Function
    • 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 the item rule in the Rules tab of the General Information page of the Edit Rule Set: <Validate Attachment> for the change order.

    InvokeGlobalFunction("hasAML", [ChangeHeader].[Change Header Main].[Change ID])

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

    This image displays the function to be invoked for items with AML

  4. Configuring the exit criteria.

    Add the hasAML rule as the exit criteria for open status.This image shows the exit criteria for status change