How to resolve the cancel button functionality is not working in purchase history page.

After the NetSuite update for the Suite Commerce and Suite Commerce standard websites getting effected, In the standard purchase history page the cancel order is not working as required, using below patch we can resolve the issue.

To resolve these issue update these functions in an extension or SSP as required

JavaScript:

OrderHistory.Cancel.View

confirm: function (){
			var self = this;
			var recordTypeParam = { recordtype: 'salesorder' };
			this.model.set('status', 'cancelled', { silent: false });
			this.model.save(recordTypeParam).done(function(result){
				self.model.addToCache(result, recordTypeParam);
			});
		}

SuiteScrupt:

OrderHistory.Model

update: function (id, data, headers) {
				var result = 'OK';


				if (data.status === 'cancelled') {


					var url = 'https://' + Application.getHost() + '/app/accounting/transactions/salesordermanager.nl?type=cancel&xml=T&id=' + id
					var cancelResponse = nlapiRequestURL(url, JSON.stringify(data), headers);
					var code = cancelResponse.getCode();
					if (code === 500 &&cancelResponse.getBody().toString().indexOf('INSUFFICIENT_PERMISSION') !== -1) {
						cancelResponse = nlapiRequestURL(url, null, headers);
						code = cancelResponse.getCode();
					}


					if (code === 206) {
						if (nlapiLookupField('salesorder', id, 'statusRef') !== 'cancelled') {
							result = 'ERR_ALREADY_APPROVED_STATUS';
						} else {
							result = 'ERR_ALREADY_CANCELLED_STATUS';
						}
					}
				}


				return result;
			}

Leave a comment

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