cancel
Showing results for 
Search instead for 
Did you mean: 

API_PROJECT_V3(Create multiple WBS nodes and Get Next Available Project Number)

marcelom_bovo
Participant
0 Kudos
235

Hello community. 

I'm trying to create a PS Project(CJ20N) using the API_PROJECT_V3 from Integration Suite and I'm having two problems which I'm not sure what's the best way to solve. 

When I'm going to create the Project, the sending system gives me an existing Project Number so I can use as template, with this Number I also should get the next available number and create it, on S4 I can use the FM CN_SUCHE_FREIE_NUMMER to do that, but it's not an RFC and I didn't find any API to get that number. Is there any way I didn't find or should I create a wrapper for this FM?

My other problem is that I'm trying to copy the WBS structure from the template project into the new one. For that I first read the old Project and then use its data on the POST function. But on the Help Portal I don't find any field to make the link between children and parent WBS nodes. I think I can use WBSElementParentInternalID even though it's not documented on the CREATE structure, but I'm not sure how to fill it since when creating I still don't have the Internal ID

Thanks in advance

View Entire Topic
marcelom_bovo
Participant
0 Kudos

To get the Next available number I used the same API API_PROJECT_V3 to get a list of Projects(ProjectExternalID) and based on that list I made a groovy code to assign the lowest free number to property NewProjectNumber

 

// Process Data
def Message processData(Message message) {
    def parser = new XmlParser()

    def body = message.getBody(java.lang.String);
    def root = parser.parseText(body)

    //Get the projectExternalIDs into a list
    def projectExternalIDs = root.'Project_Type'.'ProjectExternalID'.collect { it.text() }.sort()


    def nextNumber = 0

    //Loop through the projectExternalIDs
    for (ProjectID in projectExternalIDs) {

        //Get the number part of the external ID
        def numberPart = ProjectID.replaceAll("\\D", "")

        //If the nextNumber is 0(first pass on loop), set it to the numberPart
        if (nextNumber == 0)
            nextNumber = numberPart.toInteger()

        //If the numberPart is greater than the nextNumber, then we have found the next project
        if (numberPart.toInteger() > nextNumber) {

            def paddedNextNumber = String.format("%0" + numberPart.length() + "d", nextNumber)
            def nextProject = ProjectID.replaceAll("\\d*\$", "") + paddedNextNumber
            break
        } else

        //Possible next project
            nextNumber = numberPart.toInteger() + 1
        def paddedNextNumber = String.format("%0" + numberPart.length() + "d", nextNumber)
        nextProject = ProjectID.replaceAll("\\d*\$", "") + paddedNextNumber

    }

    message.setProperty("NewProjectNumber", nextProject);
    return message;

}