Introduction
This document intended to provide a detailed guide and examples on how to write EKL script to change maturity state of any object using Web service.
Version – Validated on 2022x FD01 (FP2205) & 2023x FD02 (FP2314)
Pre-requisites
Licenses – In order to execute this script successfully, user must have below licenses assigned:
Sr. No | License | Use |
|---|---|---|
1 | CSV |
|
2 | PPL |
|
3 | KDI |
|
Disclaimer: Licenses mentioned above are as per 2022x & 2023x documentation.
Logical Flow
Below is the logical flow of the script to change maturity:
Example
Below is the ready to use EKL script. In order to use this script, create an Knowledge Action as specified in the how to deploy section of the script.
This script is capable to change maturity of selected item as well as whole structure below it. A dialogue box will ask the user for his preference.
Detail Explanation
This script support object given below:
- Product Item.
- Resource Items.
- Mfg. Items.
- Systems and Operations.
Option to change maturity of children
When the script executes, it will ask user "Whether to change maturity of children's of selected items as well?". If user selects yes, maturity of selected item as well as its children's will be changed. Otherwise, maturity of selected item will be changed only.
The code given below is responsible to show the dialogue box.
//Show dialogue box to ask user whether to set maturity of root or all its children's as well
set ChangeMaturityOfChildrens = Question("Do you want to change maturity of children's of selected items as well?")A list of objects is created.
- If user selects "Yes", selected item and its child's will be added in list.
- If user selects "No", then only selected item will be added in list.
Objects in the list will get their maturity changed.
The code given below will manage the items to add in the list:
listOfObjects->AddItem(selPLMObject, 1) //Add root objectin the list
If ChangeMaturityOfChildrens
{
listOfChildObjects = selPLMObject->Query("PLMCoreReference", "") //This will contain all children's of selected root.
listOfObjects = listOfObjects + listOfChildObjects //combine both the lists
}Selecting Web Service URI to get Physical ID
To perform any modification on object using web service, we need it's object ID. Web service URI to get Physical ID are different for different types.
At the start of the code, there are strings defined for each type of objects , which contains all subtypes available in that type. For example:
set strMfgItemType = "CreateAssembly;Provide;Transform;Fasten;Installation;CreateMaterial;CreateKit;ElementaryEndItem;PreDrill;Drill;NoDrill;Cutting;Grinding;Beveling"
These strings will be used in "IF Else" blocks conditions to select URI according to type of object. Code for this is available in attached script between below lines/comments:
/*----Section of code to select web service URI according to object type----------------------*/ . . /*----End of: Section of code to select web service URI according to object type--------------*/
How to select desired maturity state?
While changing maturity state the next available state of object depends on its current maturity state. For example, if the current state of object is “PRIVATE”, then it can only go to “IN_WORK” state.
Other Conditions are as given below:
Current Maturity State | Next Possible Maturity State |
|---|---|
PRIVATE | IN_WORK |
IN_WORK | FROZEN, PRIVATE, RELEASED |
FROZEN | RELEASED, IN_WORK |
RELEASED | OBSOLETE ( From RELEASED, it can only go to OBSOLETE state) |
OBSOLETE | Not possible to change once changed to OBSOLETE |
It is important to know the current maturity state in order to set next maturity state. Code in the attached EKL script between comments given below will be responsible to get current maturity of object:
/*-------SECTION TO GET Maturity State of Selected Object -----*/ . . /*-------End Of: SECTION TO GET Maturity State of Selected Object -----*/
Once the current maturity state is found, we need to decide the next state to be set. The code between below given comments will ask user for the desired maturity state according to current maturity state:
/*-------SECTION TO select next maturity state. -----*/ . . /*-------SECTION TO select next maturity state. -----*/
Below is the example dialogue box:
Note:
The above two sections executes only for Root object or selected Item and not for its children’s. This is done to avoid excessive popups. So, it is important that, current maturity states of selected item and its children’s must be same. Otherwise, maturity will remain unchanged for child items, whose current maturity state is different than parent. In this case, user can run the script separately for such item.
How to set the selected maturity state?
Once the user selects the maturity state to be set, a "Post" request is sent to the webservice which changes the maturity of the object. A string (JSON String) containing information of the object is sent to the web service as a payload.
The URI of the web service is as given below:
| Method | Path |
|---|---|
| Post | /resources/v1/modeler/dslc/maturity/changeState |
The above web service works for all types of objects.
The JSON String is constructed as given below:
//Construct the JSon to be sent
jsonBody = "{"
jsonBody = jsonBody + "\\"data\\":[{\\"id\\":\\"" + OBJPhysID + "\\","
jsonBody = jsonBody + "\\"nextState\\":\\"" + strMaturityToSet + "\\","
jsonBody = jsonBody+ "}]}" Here,
- OBJPhysID: Physical ID of the Object, for which we want to change maturity.
- strMaturityToSet: Maturity state to be set. possible values are IN_WORK, PRIVATE, FROZEN, RELEASED, OBSOLETE.
Note: If the request is sent with "nextState" as blank, next possible maturity state will be set randomly.
The code between below comments in attached script is responsible to change maturity of objects.
/*-------SECTION TO SET Maturity State of Selected Object -----*/ . . /*---- End Of: SECTION TO SET MATURITY State of Selected Object --------*/
How to deploy
In order to use this script, follow below steps:
1. Download the attached EKL script.
2. Create a knowledge action.
3. Copy and paste the content of attached EKL script in the newly created action.
4. Set the input arguments as mentioned in the script and click apply.
5. Execute the script and select the input arguments.
6. Click ok.
How to create knowledge action?
References link
2022x Web Service Documentation
2023x Web Service Documentation
Author
Person of Contact - @KA
