ITK Program to update BOM Line Attribute

Requested topic by our subscriber Shubham Pawar.




Use case/Requirement: To update BOM Line attribute of children for the given item revision. Input: Item Revision tag


This is one of the frequent use case/requirement in ITK programming. To update BOMLine attribute via ITK, the BOM line attribute update program is widely used in handlers as well as standalone ITK programs.

BOM Line attribute update function:


The logic of the BOMLine attribute update function is very similar to manual update of attribute in Structure Manger.


UI Command Vs ITK Call:

Open Structure Manger -> Create BOM Window

Find and Load item revision -> Set window top line call

Set revision rule -> Set window config rule

Save-> BOM window save

Close structure -> BOM window close


To Update quantity of all children(one level) for the given parent item revision with values as 10:

Code snippet

Line number #6 - BOM_create_window

First step is to create a new BOM window using the api int BOM_create_window(tag_t * window). The function returns the tag of newly created window.


Line number #10 - CFM_find

Search for revision rule using the api int CFM_find(const char * name,tag_t * rule). The function takes revision rule as input and returns revision rule tag if found int he database.


Line number #13 - BOM_set_window_config_rule

Sets the revision rule for the newly created window. API int BOM_set_window_config_rule (tag_t window,tag_t config_rule) takes 2 inputs - window tag and revision rule tag obtailed from line number #10.

Line number #10 & #13 are optional. In case if these 2 api's are not used, the window is loaded using the default revision rule configured using preference.


Line number #17- BOM_set_window_top_line

Once the window is opened with required revision rule, the next step is load the parent item revision.

API int BOM_set_window_top_line (tag_t window, tag_t item, tag_t tem_revision, tag_t bv , tag_t * top_bom_line) takes 4 input parameters and returns top bom line as output.


Parameters:

window(I) Window to set BOM on

Item(I) Item for top line of Bill (can be NULLTAG)

Item_revision(I) Item revision for top line of Bill (if item is NULLTAG)

bv(I) View to use (NULLTAG implies use default)

top_bom_line(O) Returned top BOM line set on window


Line number #22 - BOM_line_ask_child_lines

Lists the visible bom line child items for the given parent bom line tag (single level). Based on the configured revision rule the child items are returned from database. API lists only single level structure components. To list all levels of children, either use the api in recurse way or use BOM_line_ask_all_child_lines API.


int BOM_line_ask_child_lines(tag_t bom_line, int * count, tag_t ** children)


Parameters

bom_line(I) Parent BOM line whose children are wanted

count(O) Number of child lines returned

children(OF) Returned Child lines


Line number #26 - Child Loop

For our use case we need to update all the children for the parent. From child lines tag obtained from line number #22, we have to run the child lines in the loop to get the individual children and update each children.


Line number #29 - BOM_line_look_up_attribute

API list the attribute id for the specified BOM Line attribute. API takes attribute name as input and returns attribute id. int BOM_line_look_up_attribute(const char * attribute_name, int * attribute).


Line number #30 - BOM_line_set_attribute_string

API to set value to the given BOM line tag and attribute. int BOM_line_set_attribute_string (tag_t bom_line,int attribute, const char * value).


Line number #37 - BOM_save_window

Once the values are set in the BOM windows, the window has to be saved similar to structure manager. API int BOM_save_window (tag_t window).

Any changes to the structure of the Bill in the window do not get saved to the database until this function BOM_save_window is called.


Line number #39 - BOM_close_window

Last step is to close the BOM window using API int BOM_close_window (tag_twindow).

Any changes to the structure of the bill in the window will be lost unless the BOM_save_window function is called first.


Note:

BOM window can further configured based on the requirement. For this simple use case those are not configured. Eg: To Pack all BOM Lines.


Code snippet to copy:

void updateBOMLineAttribute (tag_t tItemRevision)
{
	int ifail = ITK_ok;
    
    tag_t tWindow = NULLTAG;
    ifail = BOM_create_window(&tWindow);
    if (ifail != ITK_ok) { /* your error logic here */ }
	
	tag_t tRule= NULLTAG;
    ifail = CFM_find("Latest Working", &tRule);
    if (ifail != ITK_ok) { /* your error logic here */ }
	
	ifail = BOM_set_window_config_rule(tWindow, tRule);
    if (ifail != ITK_ok) { /* your error logic here */ }
	
	tag_t tBOMTopLine = NULLTAG;
    ifail = BOM_set_window_top_line(tWindow, NULLTAG, tItemRevision, NULLTAG, &tBOMTopLine);
    if (ifail != ITK_ok) { /* your error logic here */ }
	
	int iChildLinesCount = 0;
	tag_t* tChildLines = NULL;
	ifail = BOM_line_ask_child_lines(tBOMTopLine, &iChildLinesCount, &tChildLines);
	
	if (ifail == ITK_ok)
	{
		for (iCounter = 0; iCounter < iChildLinesCount; iCounter++)
		{
			int iSeqNoAttribute = 0 ;
			ifail = BOM_line_look_up_attribute("bl_sequence_no", &iSeqNoAttribute);
			ifail = BOM_line_set_attribute_string(tChildLines[iCounter], iSeqNoAttribute, "10");		
			if (ifail != ITK_ok) { /* your error logic here */ }
			
		}
		SAFE_SM_FREE(tChildLinesChild);
	}
	
	ifail = BOM_save_window(tWindow)
	if (ifail != ITK_ok) { /* your error logic here */ }
	
	ifail = BOM_close_window(tWindow);
	if (ifail != ITK_ok) { /* your error logic here */ }
}