Home Forums Getting Started How to call method when new revision of Item is created

This topic contains 3 replies, has 2 voices, and was last updated by  Maddy 1 week, 4 days ago.

Viewing 4 posts - 1 through 4 (of 4 total)
  • Author
    Posts
  • #10442

    Maddy
    Participant

    Hi experts,

     

    I want to call a method, when new revision of an item is created, in that method I start the workflow for new revision of an Item.

    so on which server event should I call “startWF” method?

    Thanks,

    Maddy.

     

    #10443

    Hi Maddy,

    If you want to call this Method whenever the generation of an Item is increased, you can call it from an onAfterVersion server event on the ItemType.

    If you want to call this Method for every increment of the “major_rev” property, there is no built in event to handle this. However, you can call the following Methods from an onBeforeVersion/onAfterVersion server event to check if the major_rev has been increased between them.

    onBeforeVersion:

    
    
    Innovator inn = this.getInnovator();
    
    // Get the major_rev before the version
    Item myPart = inn.newItem("Part", "get");
    myPart.setID(this.getID());
    myPart.setAttribute("select", "major_rev");
    myPart = myPart.apply();
    string prevRev = myPart.getProperty("major_rev");
    
    RequestState.Add("prevRev", prevRev); // Add value to SessionState
    return this;

    onAfterVersion:

    
    
    Innovator inn = this.getInnovator();
    
    string prevRev = (string)RequestState["prevRev"];
    
    // Get the most recent version of this item
    Item newItem = inn.newItem("Part", "get");
    newItem.setProperty("config_id", this.getProperty("config_id"));
    newItem.setProperty("is_current", "1");
    newItem.setAttribute("select", "major_rev");
    newItem = newItem.apply();
    string currRev = newItem.getProperty("major_rev");
    
    // If the major_rev's are not equal, the item has been versioned
    if (prevRev != currRev)
    {
    // Put logic here
    }
    
    return this;

    Any logic you want to run when an item is versioned can be placed in the if statement in the onAfterVersion event.

    Chris

    _______________________

    Christopher Gillis

    Aras Labs Software Engineer

    #10447

    Maddy
    Participant

    Thank you so much for you reply.

    I add my logic of start workflow in that if condition it works fine, but the life cycle state of the item will not promoted when I complete my task.

    It should get change from In work to review, so for that we have to promote life cycle through coding?

    and  one more question after workflow gets start from coding, when task is created in My Inbasket, the Worked Item is showing Restricted.

    #10448

    Maddy
    Participant

    Hi Chris,
    I add logic of promote Item, which helps me to promote Item from one state to other when I complete a task, but one problem still persist that Worked Item in My InBasket still showing as “Restricted

Viewing 4 posts - 1 through 4 (of 4 total)

You must be logged in to reply to this topic.