Get Quote Details — Restlet

Restlet to receive the Quote id and then send back the Quote details. The Quote details are send back as JSON object. Magento NetSuite integration example. The Quote details shown on the website is using this restlet

/*******************************************************************************
 * 
 * Developer: Anukaran & Suravi Lahiri Development Head: Mr. Sumeet Kulkarni
 * Company Name: CEINO Purpose: Getting value from an existing quotation through
 * restlet
 * 
 * Updation : Anukaran Testing : Anukaran & Suravi Lahiri Date : 18/09/17
 * //change the result for fetching the quote internal id using savedsearch.
 * 
 * © Copyright All Right
 * 
 ******************************************************************************/

function POST_getting_data(datain) {
	nlapiLogExecution('DEBUG', 'RESTLET GET', 'IN POST');
	var quoteObj = datain.data;
	var responseObj = new Array();
	responseObj['message'] = '';
	responseObj['responseCode'] = '';
	responseObj['customer_name'] = '';
	responseObj['date'] = '';
	responseObj['status'] = '';
	responseObj['probablity'] = '';
	responseObj['expect_date'] = '';
	// responseObj['shiping_carrier']='';
	responseObj['shipaddress'] = '';
	responseObj['billaddress'] = '';
	responseObj['line_item'] = '';
	responseObj['line_item_part'] = '';
	responseObj['line_item_amt'] = '';
	responseObj['line_item_qty'] = '';
	responseObj['department'] = '';
	responseObj['shipping_cost'] = '';
	responseObj['customer_email'] = '';
	responseObj['quote_type'] = '';
	// Start:LMS Dropbox
	var quote_id = datain.quote_id; // (send by other company)
	nlapiLogExecution('DEBUG', 'RESTLET GET', 'customer==' + quote_id);

	// Create a savedsearch on quote

	var filter = new Array(); // create filter
	filter[0] = new nlobjSearchFilter('mainline', null, 'is', true); // mainline
	// use
	// for
	// remove
	// the
	// duplicascy
	// in
	// terms
	// of
	// serching
	// a
	// items
	filter[1] = new nlobjSearchFilter('tranid', null, 'is', quote_id); // tranid
	// is
	// inter
	// id of
	// Estimate
	// in
	// quote
	// record
	var column = new Array(); // create array object
	column[0] = new nlobjSearchColumn('internalid'); // transid is internal
	// id of #order
	var search_result = nlapiSearchRecord('estimate', null, filter, column); // quote
	// is
	// datatype
	// of
	// estimate
	// on
	// form
	nlapiLogExecution('DEBUG', 'Anukaran-log', 'Search result = '
			+ search_result);
	var search_len = search_result.length;
	nlapiLogExecution('DEBUG', 'Anukaran-log', 'Search result length = '
			+ search_len);
	var tran_id = search_result[0].getId();
	nlapiLogExecution('DEBUG', 'Anukaran-log', 'transaction number = '
			+ tran_id);
	/*
	 * var customer_id = datain.customer_id; nlapiLogExecution('DEBUG','RESTLET
	 * GET','customer=='+customer_id);
	 */
	var rec_quote = nlapiLoadRecord('estimate', tran_id); // load record
	nlapiLogExecution('DEBUG', 'PBTI-log', 'LoadRecord =' + rec_quote);
	var quote_cust_name = rec_quote.getFieldText('entity'); // get customer name
	nlapiLogExecution('DEBUG', 'PBTI-log', 'Customer Name =' + quote_cust_name);
	var cust_contact_id = rec_quote.getFieldValue('custbody_nugen_contact'); // get
	// customer
	// ID
	nlapiLogExecution('DEBUG', 'PBTI-log', 'Customer contact id ='
			+ cust_contact_id);
	var quote_date = rec_quote.getFieldValue('trandate'); // get date
	nlapiLogExecution('DEBUG', 'PBTI-log', 'Existing Date =' + quote_date);
	var quote_status = rec_quote.getFieldText('entitystatus'); // get status
	nlapiLogExecution('DEBUG', 'PBTI-log', 'Existing Status =' + quote_status);
	var quote_probablity = rec_quote.getFieldValue('probability'); // get
	// probability
	nlapiLogExecution('DEBUG', 'PBTI-log', 'Existing Probablity ='
			+ quote_probablity);
	var quote_expect_date = rec_quote.getFieldValue('expectedclosedate'); // get
	// expectedclosedate
	nlapiLogExecution('DEBUG', 'PBTI-log', 'Existing quote date ='
			+ quote_expect_date);
	// var quote_shiping_carrier = rec_quote.getFieldText('shipcarrier'); // get
	// shipcarrier
	// nlapiLogExecution('DEBUG','PBTI-log','ShipCarrier ='
	// +quote_shiping_carrier);
	var quote_ship_address = rec_quote.getFieldValue('shipaddress'); // get
	// Ship
	// address
	nlapiLogExecution('DEBUG', 'PBTI-log', 'quote_ship_address ='
			+ quote_ship_address);
	var quote_bill_address = rec_quote.getFieldValue('billaddress'); // get
	// Bill
	// address
	nlapiLogExecution('DEBUG', 'PBTI-log', 'quote_bill_address ='
			+ quote_bill_address);
	var quote_lineitem_count = rec_quote.getLineItemCount('item');
	nlapiLogExecution('DEBUG', 'PBTI-log', 'LineCount =' + quote_lineitem_count);
	var line_number = quote_lineitem_count;
	nlapiLogExecution('DEBUG', 'PBTI-log', 'LineNumber =' + line_number);
	var department = rec_quote.getFieldText('department');
	;
	nlapiLogExecution('DEBUG', 'PBTI-log', 'department =' + department);
	var shipping_cost = rec_quote.getFieldValue('shippingcost');
	;
	nlapiLogExecution('DEBUG', 'PBTI-log', 'shipping_cost =' + shipping_cost);
	var quote_type = rec_quote.getFieldText('custbody_quote_types');
	nlapiLogExecution('DEBUG', 'PBTI-log', 'quote_type =' + quote_type);

	var customer_email = nlapiLookupField('contact', cust_contact_id, 'email');
	nlapiLogExecution('DEBUG', 'PBTI-log', 'customer_email =' + customer_email);

	var j = 1;
	var item_id = new Array();
	var amt = new Array();
	var partNo = new Array();
	var quantity = new Array();

	for (var i = 1; i <= line_number; i++) {
		// item_id = rec_quote.getLineItemValue('item','item',i);
		item_id.push(rec_quote.getLineItemValue('item', 'item', i));
		nlapiLogExecution('DEBUG', 'RESTLET POST', 'Item_id==' + item_id[i]);
		partNo
				.push(rec_quote.getLineItemValue('item', 'custcol_partnumber',
						i));
		amt.push(rec_quote.getLineItemValue('item', 'amount', i));
		nlapiLogExecution('DEBUG', 'RESTLET POST', 'Amount==' + amt[i]);
		quantity.push(rec_quote.getLineItemValue('item', 'quantity', i));
		nlapiLogExecution('DEBUG', 'RESTLET POSTquantity', 'quantity=='
				+ quantity[i]);
		j++;
		rec_quote.commitLineItem('item');

	}

	responseObj['message'] = 'Record Value Get Through Script';
	responseObj['responseCode'] = '1'; // manual code any thing instead of 1
	// responseObj['record_id'] = record_id; // when create record then its
	// mendatory
	// responseObj['Sales_Id']=nlapiLookupField('estimate', record_id,
	// 'tranid');
	responseObj['customer_name'] = quote_cust_name; // take any variable name
	// this side = take upper
	// variable name this side
	responseObj['date'] = quote_date; // take any variable name this side =
	// take upper variable name this side
	responseObj['status'] = quote_status; // take any variable name this side
	// = take upper variable name this
	// side
	responseObj['probablity'] = quote_probablity; // take any variable name
	// this side = take upper
	// variable name this side
	responseObj['expect_date'] = quote_expect_date; // take any variable name
	// this side = take upper
	// variable name this side
	// responseObj['shiping_carrier']=quote_shiping_carrier; // take any
	// variable name this side = take upper variable name this side
	responseObj['shipaddress'] = quote_ship_address; // take any variable
	// name this side = take
	// upper variable name
	// this side
	responseObj['billaddress'] = quote_bill_address;
	responseObj['line_item'] = item_id; // take any variable name this side =
	// take upper variable name this side
	responseObj['line_item_part'] = partNo;
	responseObj['line_item_amt'] = amt;// take any variable name this side =
	// take upper variable name this side
	responseObj['line_item_qty'] = quantity;

	responseObj['department'] = department; // take any variable name this side
	// = take upper variable name this
	// side
	responseObj['shipping_cost'] = shipping_cost;
	responseObj['customer_email'] = customer_email;
	responseObj['quote_type'] = quote_type;

	// Making JSONobj -> var JSONObj =
	// {"message":responseObj['message'],"responseCode":responseObj['responseCode'],"data":[{"Label:responseObj['VariableName
	// Those taken above']},{"Label2:responseObj['VariableName Those taken
	// above2']}]}

	nlapiLogExecution('DEBUG', ' responseObj[line_item]', 'responseObj ='
			+ responseObj['line_item'][1]);

	var itemarray = [];

	// for(var i=0;i<responseObj['line_item'].length;i++){
	// var itemobj={};
	//
	// itemobj.item_id = responseObj['line_item'][i];
	//		
	// itemobj.part_number = responseObj['line_item_part'][i];
	// itemobj.amt = responseObj['line_item_amt'][i];
	// itemobj.quantity = responseObj['line_item_qty'][i];
	// itemarray.push(itemobj);
	// }
	for (var i = 0; i < responseObj['line_item'].length; i++) {
		var itemobj = {};

		itemobj.item_id = responseObj['line_item'][i];

		itemobj.part_number = responseObj['line_item_part'][i];
		itemobj.amt = responseObj['line_item_amt'][i];
		itemarray.push(itemobj);
	}
	nlapiLogExecution('DEBUG', ' itemarray', itemarray);

	var JSONObj = {
		"message" : responseObj['message'],
		"responseCode" : responseObj['responseCode'],
		"data" : [ {
			"customer_name" : responseObj['customer_name']
		}, {
			"date" : responseObj['date']
		}, {
			"status" : responseObj['status']
		}, {
			"Probablity" : responseObj['probablity']
		}, {
			"expected_date" : responseObj['expect_date']
		}, {
			"quote_ship_address" : responseObj['shipaddress']
		}, {
			"quote_bill_address" : responseObj['billaddress']
		}, {
			"items" : itemarray
		}, {
			"Department" : responseObj['department']
		}, {
			"Email" : responseObj['customer_email']
		}, {
			"Quote_Type" : responseObj['quote_type']
		}, {
			"shipping-cost" : responseObj['shipping_cost']
		} ]
	};

	return JSONObj;

}

Leave a comment

Your email address will not be published. Required fields are marked *