Skip to Content
0
Apr 15, 2020 at 05:12 PM

Help with the implementation of a Custom code

72 Views

Hello Experts.

Again I come here to ask for a little help or guidance to complete my problem.

A few days ago, I commented that I needed to obtain several records from an Excel table, to be able to add them in the Order Quantity section.

The Excel table counts at the moment for tests with 5 records. That starts in B2 with the title and data from B3 to B7.

They had shared the following code, but I do not understand how to make it work or how I can modify it to obtain the data individually.

GLOBAL.step({ Read_Excel_Content: function(ev, sc, st) {
	var rootData = sc.data;
	ctx.workflow('PO_Conf', 'de68cb4e-3ffb-4ebc-ad56-bd1016984ff0') ;
	// Read Excel Content
	updateProgressPopup('Initializing Excel...');
	ctx.excel.initialize();
	updateProgressPopup('Processing data from Excel file');
	ctx.excel.file.open(rootData.excelFilePathFromUser);
	ctx.log('INFO:: Excel file opened');
	var rowStartIndex=2;
	var poObject, itemObj, poMap = {},poNumber;
	rootData.POs = [];
	var x;
	if(ctx.excel.sheet.getCell(1,'A')=="Purchase Order")
	{
	for(x=rowStartIndex;ctx.excel.sheet.getCell(x,'A') ;x++)
	{
		poNumber = ctx.excel.sheet.getCell(x,'A').toString();
		if(!poMap[poNumber])
		{
			poMap[poNumber] = {PO:poNumber,items:[]};
			rootData.POs.push(poMap[poNumber]);
		}
		poMap[poNumber].items.push({
			itemNo: 				getStringOrBlank(ctx.excel.sheet.getCell(x,'B')),
			confControl:		getStringOrBlank(ctx.excel.sheet.getCell(x,'C')),
			orderAck:				getStringOrBlank(ctx.excel.sheet.getCell(x,'D')),
			CC:							getStringOrBlank(ctx.excel.sheet.getCell(x,'E')),
			D:							getStringOrBlank(ctx.excel.sheet.getCell(x,'F')),
			deliveryDate:		getStringOrBlank(ctx.excel.sheet.getCell(x,'G')),
			time:						getStringOrBlank(ctx.excel.sheet.getCell(x,'H')),
			quantity:				getStringOrBlank(ctx.excel.sheet.getCell(x,'I')),
			reference:			getStringOrBlank(ctx.excel.sheet.getCell(x,'J')),
			createdOn:			getStringOrBlank(ctx.excel.sheet.getCell(x,'K'))
		});
	}
	//sort items in ascending order for each PO
	for(var i=0;i<rootData.POs.length;i++)
	{
		rootData.POs[i].items.sort(itemObjectCompareForSort);
	}
	rootData.poMap = poMap;
	ctx.log('INFO: Excel content processed. Number of POs '+rootData.POs.length+ '. Total items: '+ (x-rowStartIndex) );
	//ctx.excel.file.close();
	//ctx.excel.end();
	sc.endStep(); // Open_PO_Conf_page
	return;
		}
	// To handle wrong input format
	else {
		ctx.log('INFO:: Input Excel not processed since the format is wrong');
		rootData.automationResult = {type:'Error',text:'Step for reading excel content, wrong input format. Please check the template.'};
		//openBreakPopup(sc);
		closeProgressPopup();
		sc.endScenario();
	}
}});

I put it in a step called Custom, but I still don't understand how I can use it or how I can make it work properly.

try to put the code in the Custom section but it doesn't work, since when executing this step, it sends me an error.

So you came to ask if you could help me to get the different records? Or, how should I do it in order to obtain the necessary data and use it?

Likewise, can each one be saved independently or are they stored in an array?

Any help is welcome.

Thank you very much in advance.

Regards.

Edson.

Attachments

custom.png (121.5 kB)
custom-codigo.png (208.5 kB)
custom-codigo.png (208.5 kB)