Windchill Checkout, update and Checkin via Windchill Extension's Services

    This example is to achieve to update objects in Windchill thru extensions. It is really hard to find a resource for Windchill extension's services to take an advantage of them. So, I wrote a simple example to update objects in Windchill from Thingworx.

     

    There are three data shapes needed to do this.

    One is "PTC.PLM.WindchillPartUfids" which has only "value" field (String) in it and another is "PTC.PLM.WindchillPartCheckedOutDS" which has a "ufid" field (String). Last one is "PTC.PLM.WindchillPartPropertyDS" which has a "ufid" field (String) and fields for "attributes". For an instance of the last data shape, there might be three fields as "ufid", "partPrice" and "quantity" to update parts. In this example, this data shape has two fields which are "ufid" and "almProjectId".

     

    In this example, this needs two input parameters. One is ufid (String) and almProjectId (String). If you need to have multiple objects to update at once, you can use InfoTable type as an "ufid" input parameter instead of String type.

     

    Note that this is an example code and need to handle exceptions if needed.

     

    // To 
    var params = {
        infoTableName : "InfoTable",
        dataShapeName : "PTC.PLM.WindchillPartUfids"
    };
    
    // CreateInfoTableFromDataShape(infoTableName:STRING("InfoTable"), dataShapeName:STRING):INFOTABLE(PTC.PLM.WindchillPartUfids)
    var ufids = Resources["InfoTableFunctions"].CreateInfoTableFromDataShape(params);
    
    // PTC.PLM.WindchillPartUfids entry object
    var newValue = new Object();
    newValue.value = ufid; // STRING
    
    ufids.AddRow(newValue);
    
    // Check out
    var params = {
        ufids: ufids /* INFOTABLE */,
        comment: undefined /* STRING */,
        dataShape: "PTC.PLM.WindchillPartCheckedOutDS" /* DATASHAPENAME */
    };
    
    // checkedOutObjs: INFOTABLE dataShape: "undefined"
    var checkedOutObjsFromService = me.CheckOut(params);
    
    var params = {
        infoTableName : "InfoTable",
        dataShapeName : "PTC.PLM.WindchillPartUfids"
    };
    
    // CreateInfoTableFromDataShape(infoTableName:STRING("InfoTable"), dataShapeName:STRING):INFOTABLE(PTC.PLM.WindchillPartUfids)
    var checkedOutObjs = Resources["InfoTableFunctions"].CreateInfoTableFromDataShape(params);
    
    try {
        var tableLength = checkedOutObjsFromService.rows.length;
        
        for (var x = 0; x < tableLength; x++) {
            var row = checkedOutObjsFromService.rows[x];
            
            // PTC.PLM.WindchillPartUfids entry object
            var checkedOutObj = new Object();
            checkedOutObj.value = row.ufid.substring(0,row.ufid.lastIndexOf(":")); // STRING
            
            //logger.warn("UFID : " + checkedOutObj.value);
            checkedOutObjs.AddRow(checkedOutObj);
    
            /* Update Objects in Windchill */
            var params = {
                infoTableName : "InfoTable",
                dataShapeName : "PTC.PLM.WindchillPartPropertyDS"
            };
    
            // CreateInfoTableFromDataShape(infoTableName:STRING("InfoTable"), dataShapeName:STRING):INFOTABLE(PTC.ALM.WindchillPartPropertyDS)
            var wcInfoTable = Resources["InfoTableFunctions"].CreateInfoTableFromDataShape(params);
    
            // PTC.ALM.WindchillPartPropertyDS entry object
            var newEntry = new Object();
            newEntry.ufid = checkedOutObj.value; // STRING
            newEntry.almProjectId = almProjectId; // STRING
    
            wcInfoTable.AddRow(newEntry);
    
            var params = {
                objects: wcInfoTable /* INFOTABLE */,
                modification: "REPLACE" /* STRING */,
                dataShape: "PTC.PLM.WindchillPartCheckedOutDS" /* DATASHAPENAME */
            };
    
            // result: INFOTABLE dataShape: "undefined"
            var result = me.Update(params);
        }
    
    } catch(err) {
        logger.warn("ERROR Catched");
        var params = {
            ufids: ufids /* INFOTABLE */,
            dataShape: "PTC.PLM.WindchillPartCheckedOutDS" /* DATASHAPENAME */
        };
    
        // result: INFOTABLE dataShape: "undefined"
        var result = me.CancelCheckOut(params);    
    }
    
    var params = {
        ufids: checkedOutObjs /* INFOTABLE */,
        comment: undefined /* STRING */,
        dataShape: "PTC.PLM.WindchillPartCheckedOutDS" /* DATASHAPENAME */
    };
    
    // result: INFOTABLE dataShape: "undefined"
    var result = me.CheckIn(params);