When the opportunity form was originally set up, the person selected 'Store form with record' and now there is a new preferred form but obviously it's not getting used since the old form is stored with the record. My preferred form is the new one as well.
I've created a scheduled script to attempt to change these values but it is not working. There is a field 'win/loss reason' that generated an error: 'The Opportunity Status is set to Loss, please set the win loss reason field.'. I've removed the mandatory check box on all the relevant forms and I tried setting the ignoremandatoryfields = true on the nlapiSubmitRecord statement but that didn't seem to work. About 1/2 of all the opportunities I wanted to process don't have this field set.
I just temporarily seemed to have got around the error by using this filter
filters[0] = new nlobjSearchFilter('winlossreason', null, 'noneof', '@NONE@');...but the new forms are still not being saved with the opportunities for some reason for the processed records.Can anyone suggest a way around this? Or another way to change the opportunity form associated with all the opportunities?Also, the records that it looks like it processed before the error didn't seem to actually store the new form also for some reason. function removeStoredOpportunityForm() { var context = nlapiGetContext(); var usageRemaining = context.getRemainingUsage(); var objSearchResultArray = []; var opportunityID; var opportunityRecord; var storedForm; objSearchResultArray = getSearchResults(); if (objSearchResultArray !=null && objSearchResultArray.length > 0) { nlapiLogExecution('DEBUG', 'objSearchResultArray', 'objSearchResultArray length = ' + objSearchResultArray.length); for (var intSearchIndex = 0; intSearchIndex < 700 ; intSearchIndex ++) { // objSearchResultArray.length ; intSearchIndex ++) { // Not all while testing nlapiLogExecution('DEBUG', 'removeStoredOpportunityForm', 'Attempting to iterate search results. intSearchIndex = ' + intSearchIndex); usageRemaining = context.getRemainingUsage(); if (usageRemaining > 150) { opportunityID = objSearchResultArray[intSearchIndex].getValue('internalid'); opportunityRecord = nlapiLoadRecord(objSearchResultArray[intSearchIndex].getRecordType(), opportunityID); storedForm = opportunityRecord.getFieldValue('customform'); if (storedForm != null && storedForm == '131') { nlapiLogExecution('DEBUG', 'Store Form is 131', 'Attempting to change stored form for record: ' + opportunityID + ', Old Stored form = ' + storedForm); opportunityRecord.setFieldValue('customform', '146'); nlapiSubmitRecord(opportunityRecord,false, true); // Disables mandatory fields } else if (storedForm != '131' && storedForm != '146') { nlapiLogExecution('DEBUG', 'Stored Form not 131', 'Attempting to change stored form for record: ' + opportunityID + ', Old Stored form = ' + storedForm); opportunityRecord.setFieldValue('customform', '146'); nlapiSubmitRecord(opportunityRecord,false, true); // Disables mandatory fields } else { nlapiLogExecution('DEBUG', 'Stored Form is null', 'There is no stored opportunity form'); } } else { nlapiLogExecution('DEBUG', 'Usage Exceeded', 'Script usage limit has been exceeded'); break; } } } } function getSearchResults() { var results = []; var filters = new Array(); var columns = new Array(); filters[0] = new nlobjSearchFilter('winlossreason', null, 'noneof', '@NONE@'); columns[0] = new nlobjSearchColumn('internalid'); var savedSearch = nlapiCreateSearch('opportunity', filters, columns); var resultset = savedSearch.runSearch(); nlapiLogExecution('DEBUG', 'getSearchResults', 'savedSearch run'); var searchid = 0; do { var resultslice = resultset.getResults( searchid, searchid+1000 ); for (var rs in resultslice) { results.push( resultslice[rs] ); searchid++; } } while (resultslice.length >= 1000); return results; } Any help would be appreciated.Thanks,Rob.