trying to reschedule the calim but when clicked on button spinner keeps on rotating and unable to reschedule
see the screenshots for the error
Creatfurniturecontroller.js
createFurnitureServiceInfo : function(component) {
var scheduleServiceWrapper = component.get('v.scheduleService');
var scheduleServiceWrappperComments = scheduleServiceWrapper.Comments.replace(/\\/g, '');
var escapedComments = this.encodeSpecialCharacters(scheduleServiceWrappperComments);
scheduleServiceWrapper.Comments = escapedComments;
scheduleServiceWrapper.ButtonLabel = component.get('v.buttonLabel');
component.set('v.isLoading',true);
var isIndependentServicer = component.get('v.isIndependentServicerChecked');
var independentServicer = component.get('v.independentServicer');
var action = component.get('c.createFurnitureServices');
var parameters = {
"scheduleServiceJSON": JSON.stringify(scheduleServiceWrapper),
"independentServicerJSON": JSON.stringify(independentServicer),
"isIndependentServicer": isIndependentServicer
};
//console.log('params: ' + JSON.stringify(parameters));
action.setParams(parameters);
action.setCallback(this, function(response) {
component.set('v.isLoading',false);
var state = response.getState();
if (state === "SUCCESS") {
this.displayToast('Success', 'The service has been successfully scheduled.','success');
var navEvt = $A.get("e.force:navigateToSObject");
navEvt.setParams({
"recordId": response.getReturnValue(),
"slideDevName": "detail"
});
this.closeModal(component);
this.refreshFurnitureServiceRecord();
navEvt.fire();
} else {
console.error(response.getError());
this.displayToast('Error', 'Something went wrong, the service was NOT scheduled. Please verify zip code and additional address fields.','error');
}
});
$A.enqueueAction(action);
},
refreshFurnitureServiceRecord : function() {
window.setTimeout(
$A.getCallback(function() {
var refreshFurnitureServiceEvent = $A.get("e.c:refreshFurnitureServiceEvent");
refreshFurnitureServiceEvent.fire();
}), 2000
);
},
getDayOfWeek : function(serviceDate) {
var momentDate = moment(serviceDate);
var weekDay = momentDate.format('dddd');
return weekDay;
},
formatServiceDate : function(serviceDate) {
return serviceDate.substring(5, 7) + '/' + serviceDate.substring(8, 10) + '/' + serviceDate.substring(0, 4);
},
displayToast : function(title, message, type, mode){
var toastEvent = $A.get("e.force:showToast");
toastEvent.setParams({
title : title,
message: message,
duration:' 5000',
key: 'info_alt',
type: type,
mode: mode ? mode : 'pester'
});
toastEvent.fire();
},
getRelatedCase : function(component, event, helper) {
var workspaceAPI = component.find("workspace");
workspaceAPI.getFocusedTabInfo().then(function(response) {
//console.log(JSON.parse(JSON.stringify(response)));
var parentTabId = response.parentTabId;
workspaceAPI.getTabInfo({
tabId: parentTabId
}).then(function(parentTabResponse) {
var parentTabObjectAPIName = parentTabResponse.pageReference.attributes.objectApiName;
//console.log(parentTabObjectAPIName);
// If the parent tab is a Case record
if(parentTabObjectAPIName === "Case"){
var caseRecord = {
"recordId" : parentTabResponse.recordId,
"label" : parentTabResponse.title
}
component.set('v.caseRecord',caseRecord);
} else {
// If the parent tab is not a Case record
var relatedSubTabs = parentTabResponse.subtabs;
for (let i = 0; i < relatedSubTabs.length; i++) {
var subtab = relatedSubTabs[i];
var subTabObjectAPIName = subtab.pageReference.attributes.objectApiName;
if(subTabObjectAPIName === "Case"){
var caseRecord = {
"recordId" : subtab.recordId,
"label" : subtab.title
}
component.set('v.caseRecord',caseRecord);
}
}
}
helper.fetchCaseData(component, event, helper);
});
})
.catch(function(error) {
console.log(error);
});
},
isValidToSave : function(component, event, helper) {
var validityErrors = [];
var notPopulatedRequiredFields = [];
var isIndependentServicer = component.get('v.isIndependentServicerChecked');
try {
// validation for both: regular and independent servicer scheduling
let serviceDateField = isIndependentServicer ? component.find('serviceDate2') : component.find('serviceDate');
serviceDateField.reportValidity();
if (!serviceDateField.get('v.value')) validityErrors.push('Service Date must be selected.');
let addressField = isIndependentServicer ? component.find('addressField2a') : component.find('addressField');
addressField.reportValidity();
if (!addressField.get('v.value')) notPopulatedRequiredFields.push('address');
let zipCodeField = isIndependentServicer ? component.find('zipCodeField2') : component.find('zipCodeField');
zipCodeField.reportValidity();
if (!zipCodeField.get('v.value')) notPopulatedRequiredFields.push('zip code');
let stateField = isIndependentServicer ? component.find('stateField2') : component.find('stateField');
stateField.reportValidity();
if (!stateField.get('v.value')) notPopulatedRequiredFields.push('state');
let cityField = isIndependentServicer ? component.find('cityField2') : component.find('cityField');
cityField.reportValidity();
if (!cityField.get('v.value')) notPopulatedRequiredFields.push('city');
// validation for independent servicer scheduling
if (isIndependentServicer) {
var caseRecord = component.get('v.caseRecord');
if (!caseRecord || !caseRecord.Id) validityErrors.push('Selecting case related to service is required.');
if (!caseRecord.Independent_Servicer__r) {
validityErrors.push('Independent Servicer needs to be assigned to the selected Case.');
} else if (!caseRecord.Independent_Servicer__r.Servicer_Id__c) {
validityErrors.push('Independent Servicer assigned to the selected Case needs to have Servicer Id value.');
}
let callBackContactField = component.find('callBackContact');
callBackContactField.reportValidity();
if (!callBackContactField.get('v.value')) notPopulatedRequiredFields.push('contact');
let callBackNumberField = component.find('callBackNumber');
callBackNumberField.reportValidity();
if (!callBackNumberField.get('v.value')) {
notPopulatedRequiredFields.push('phone');
} else if (callBackNumberField.get('v.value').length != 10) {
validityErrors.push('Phone field must be 10 digits long.');
}
} else {
// validation for regular scheduling
var routeCode = component.get('v.selectedRouteCode');
if($A.util.isUndefinedOrNull(routeCode) || $A.util.isEmpty(routeCode) || routeCode.trim() == ''){
validityErrors.push('A Route code is required.');
}
var selectedAvailableAppointmentUnits = Number(component.get('v.selectedAppointmentUnits'));
var availableUnits = Number(component.get('v.scheduleService.AppointmentUnits'));
if(availableUnits > selectedAvailableAppointmentUnits){
validityErrors.push('There is not enough appointment units available for the selected service date.');
}
}
if (isIndependentServicer) {
if (notPopulatedRequiredFields.length > 0) validityErrors.push('You need to populate those fields on the selected case: ' + notPopulatedRequiredFields.join(', ') + '.');
} else {
if (notPopulatedRequiredFields.length > 0) validityErrors.push('You need to populate those fields: ' + notPopulatedRequiredFields.join(', ') + '.');
}
} catch(err) {
console.error(err);
}
return validityErrors;
},
isIndependentServicerCheckedChanged : function(component, event, helper) {
let checkboxValue = component.get('v.isIndependentServicerChecked');
try{
// If the checkbox was checked
if(checkboxValue){
// Set service date as current date
component.set('v.selectedServiceDate', new Date().toISOString().slice(0, 10));
let caseRecord = component.get('v.caseRecord');
let scheduleService = component.get('v.scheduleService');
// If this property is already filled, it means the service was already scheduled once, so we should consider data from POPS
if(scheduleService.Servicer){
let independentServicer = {
CustomerName : scheduleService.CustomerName,
Address : scheduleService.Address,
ZipCode : scheduleService.ZipCode,
State : scheduleService.State,
City : scheduleService.City,
ContactPhone : scheduleService.ContactPhone,
ContactPhoneExtension : scheduleService.ContactPhoneExtension,
Servicer : caseRecord.Independent_Servicer__r.Servicer_Id__c,
CaseId : caseRecord.Id
};
component.set('v.independentServicer',independentServicer);
} else {
// This means it's the first time creating the independent servicer furniture service, so we should consider data from the associated Case
let independentServicer = {
CustomerName : caseRecord.Call_Back_Contact__c,
Address : caseRecord.Shipping_Address_1__c,
ZipCode : caseRecord.Shipping_Postal_Code__c,
State : caseRecord.Shipping_State__c,
City : caseRecord.Shipping_City__c,
ContactPhone : caseRecord.Requested_Call_Back_Number__c,
ContactPhoneExtension : caseRecord.Requested_Call_Back_Number_Ext__c,
Servicer : caseRecord.Independent_Servicer__r.Servicer_Id__c,
CaseId : caseRecord.Id
};
component.set('v.independentServicer',independentServicer);
}
} else {
component.set('v.selectedServiceDate', null);
}
} catch (err) {
console.error(err);
}
}
})
Apex class
public without sharing class CreateFurnitureServicesCtrl {
#AuraEnabled
public static ScheduleServiceWrapper getScheduleServiceWrapper(String claimRecordId){
String[] claimFieldsList = new List<String>{
'Id', 'OrderNumber__c','AccountNumber__c', 'ClaimId__c'
};
Map<String,String> claimsFieldValueMap = new Map<String,String>();
claimsFieldValueMap.put('Id',claimRecordId);
Claims__x objClaims = nfm_ExternalClaimRequest.getClaims(claimFieldsList, claimsFieldValueMap, 'Id', 'ASC')[0];
String[] orderDetailsFieldsList = new List<String>{
'Id','CustomerZip__c','CustomerPhone__c','OrderState__c','OrderCity__c','CustomerState__c','CustomerCity__c','DistributionMethod__c',
'AccountNumber__c','OrderNumber__c','OrderZip__c', 'OrderPrimaryCallAhPhExt__c', 'CustomerName__c',
'CustomerAddress1__c','CustomerAddress2__c','OrderAddress1__c','OrderAddress2__c'
};
Map<String,String> orderDetailsFieldValueMap = new Map<String,String>();
orderDetailsFieldValueMap.put('OrderNumber__c',objClaims.OrderNumber__c);
OrderDetails__x objOrderDetails = nfm_ExternalOrderDetailsRequest.getOrders(orderDetailsFieldsList, orderDetailsFieldValueMap, 'Id', 'ASC', false)[0];
ScheduleServiceWrapper objScheduleServiceWrapper = new ScheduleServiceWrapper();
objScheduleServiceWrapper.NumberOfDays = 15;
objScheduleServiceWrapper.AppointmentUnits = 1;
objScheduleServiceWrapper.StartDate = String.valueOf(System.today());
objScheduleServiceWrapper.ClaimId = objClaims.ClaimId__c;
objScheduleServiceWrapper.ServiceDate = 'TBD';
objScheduleServiceWrapper.RouteCode = 'TBD';
objScheduleServiceWrapper.ServiceCode = 'TBD';
objScheduleServiceWrapper.Comments = ' ';
FurnitureServices__x objFurnitureServices = getPreviousFurnitureService(objClaims.ClaimId__c);
Set<String> customerDistributionSet = new Set<String>{'P','T'};
Set<String> orderDistributionSet = new Set<String>{'D','W','I','O'};
// Here we're verifying if a basic field is blank, so that means that the furnite service hasn't been scheduled yet
if(objFurnitureServices.InspectAddress1__c == null){
// In this case, the details are filled according to the Order's Delivery Method
objScheduleServiceWrapper.CustomerName = objOrderDetails.CustomerName__c;
objScheduleServiceWrapper.ContactName = objOrderDetails.CustomerName__c;
objScheduleServiceWrapper.ContactPhone = objOrderDetails.CustomerPhone__c;
if(customerDistributionSet.contains(objOrderDetails.DistributionMethod__c)){ // Customer
objScheduleServiceWrapper.City = objOrderDetails.CustomerCity__c;
objScheduleServiceWrapper.State = objOrderDetails.CustomerState__c;
objScheduleServiceWrapper.ZipCode = objOrderDetails.CustomerZip__c.substring(0,5);
objScheduleServiceWrapper.Address = objOrderDetails.CustomerAddress1__c + ' ' + nfm_Utils.ifNull(objOrderDetails.CustomerAddress2__c,'');
} else if(orderDistributionSet.contains(objOrderDetails.DistributionMethod__c)) { //Order
objScheduleServiceWrapper.City = objOrderDetails.OrderCity__c;
objScheduleServiceWrapper.State = objOrderDetails.OrderState__c;
objScheduleServiceWrapper.ZipCode = objOrderDetails.OrderZip__c.substring(0,5);
objScheduleServiceWrapper.ContactPhoneExtension = objOrderDetails.OrderPrimaryCallAhPhExt__c;
objScheduleServiceWrapper.Address = objOrderDetails.OrderAddress1__c + ' ' + nfm_Utils.ifNull(objOrderDetails.OrderAddress2__c,'');
}
} else {
// In this case, the details are filled according to the previous Furniture Service
objScheduleServiceWrapper.CustomerName = objFurnitureServices.InspectName__c;
objScheduleServiceWrapper.ContactName = objFurnitureServices.ContactDescription__c;
objScheduleServiceWrapper.ContactPhone = objFurnitureServices.ContactPhone__c;
objScheduleServiceWrapper.ContactPhoneExtension = objFurnitureServices.ContactPhoneExtension__c;
objScheduleServiceWrapper.Address = objFurnitureServices.InspectAddress1__c;
objScheduleServiceWrapper.City = objFurnitureServices.InspectCity__c;
objScheduleServiceWrapper.State = objFurnitureServices.InspectState__c;
objScheduleServiceWrapper.ZipCode = objFurnitureServices.InspectZip__c.substring(0,5);
}
objScheduleServiceWrapper.Servicer = nfm_Utils.ifNull(objFurnitureServices.Servicer__c,'');
return objScheduleServiceWrapper;
}
public class ScheduleServiceWrapper{
#AuraEnabled public String ClaimId{get;set;}
#AuraEnabled public String ZipCode{get;set;}
#AuraEnabled public String StartDate{get;set;}
#AuraEnabled public String ServiceDate{get;set;}
#AuraEnabled public String ServiceCode{get;set;}
#AuraEnabled public String RouteCode{get;set;}
#AuraEnabled public Integer NumberOfDays{get;set;}
#AuraEnabled public Integer AppointmentUnits{get;set;}
#AuraEnabled public String CustomerName{get;set;}
#AuraEnabled public String Address{get;set;}
#AuraEnabled public String Servicer{get;set;}
#AuraEnabled public String State{get;set;}
#AuraEnabled public String City{get;set;}
#AuraEnabled public String ContactName{get;set;}
#AuraEnabled public String ContactPhone{get;set;}
#AuraEnabled public String ContactPhoneExtension{get;set;}
#AuraEnabled public String Comments{get;set;}
#AuraEnabled public String ButtonLabel{get;set;}
}
public class IndependentServicerWrapper{
#AuraEnabled public String CustomerName{get;set;}
#AuraEnabled public String Address{get;set;}
#AuraEnabled public String State{get;set;}
#AuraEnabled public String City{get;set;}
#AuraEnabled public String ZipCode{get;set;}
#AuraEnabled public String ContactPhone{get;set;}
#AuraEnabled public String ContactPhoneExtension{get;set;}
#AuraEnabled public String Servicer{get;set;}
#AuraEnabled public String CaseId{get;set;}
}
#AuraEnabled
public static String createFurnitureServices(String scheduleServiceJSON, String independentServicerJSON, Boolean isIndependentServicer){
ScheduleServiceWrapper objScheduleServiceWrapper = (ScheduleServiceWrapper) System.JSON.deserialize(scheduleServiceJSON, ScheduleServiceWrapper.class);
IndependentServicerWrapper objIndependentServicerWrapper = !isIndependentServicer ? null : (IndependentServicerWrapper) System.JSON.deserialize(independentServicerJSON, IndependentServicerWrapper.class);
JSONGenerator jsonGenerator = JSON.createGenerator(false);
jsonGenerator.writeStartObject();
jsonGenerator.writeObjectField('ClaimId__c', objScheduleServiceWrapper.ClaimId);
jsonGenerator.writeObjectField('Comments__c','[' + System.today().format() + '][' + nfm_Utils.userAlias + '] ' + objScheduleServiceWrapper.Comments);
String inspectDateYear = objScheduleServiceWrapper.ServiceDate.substring(0,4);
String inspectDateMonth = objScheduleServiceWrapper.ServiceDate.substring(5,7);
String inspectDateDay = objScheduleServiceWrapper.ServiceDate.substring(8,10);
jsonGenerator.writeObjectField('InspectDate__c', inspectDateMonth + '/' + inspectDateDay + '/'+ inspectDateYear);
if (!isIndependentServicer) {
//specific fields
jsonGenerator.writeObjectField('InspectName__c', objScheduleServiceWrapper.CustomerName);
jsonGenerator.writeObjectField('ServiceCode__c', objScheduleServiceWrapper.ServiceCode);
jsonGenerator.writeObjectField('RouteCode__c', objScheduleServiceWrapper.RouteCode);
jsonGenerator.writeObjectField('AppointmentUnits__c', String.valueOf(objScheduleServiceWrapper.AppointmentUnits));
//common fields
jsonGenerator.writeObjectField('InspectAddress1__c', objScheduleServiceWrapper.Address);
jsonGenerator.writeObjectField('InspectAddress2__c', '');
jsonGenerator.writeObjectField('InspectCity__c', objScheduleServiceWrapper.City);
jsonGenerator.writeObjectField('InspectState__c', objScheduleServiceWrapper.State);
jsonGenerator.writeObjectField('InspectZip__c', objScheduleServiceWrapper.ZipCode);
jsonGenerator.writeObjectField('ContactPhone__c', objScheduleServiceWrapper.ContactPhone);
jsonGenerator.writeObjectField('ContactPhoneExtension__c', nfm_Utils.IfNull(objScheduleServiceWrapper.ContactPhoneExtension,''));
}
if (isIndependentServicer) {
//specific fields
String servicerCode = Test.isRunningTest() ? '12345' : objIndependentServicerWrapper.Servicer;
jsonGenerator.writeObjectField('Servicer__c', servicerCode); //servicer 5-digit code
//common fields
jsonGenerator.writeObjectField('InspectAddress1__c', objIndependentServicerWrapper.Address);
jsonGenerator.writeObjectField('InspectAddress2__c', '');
jsonGenerator.writeObjectField();
jsonGenerator.writeObjectField('InspectCity__c', objIndependentServicerWrapper.City);
jsonGenerator.writeObjectField('InspectState__c', objIndependentServicerWrapper.State);
jsonGenerator.writeObjectField('InspectZip__c', objIndependentServicerWrapper.ZipCode);
jsonGenerator.writeObjectField('InspectName__c', objIndependentServicerWrapper.CustomerName);
jsonGenerator.writeObjectField('ContactPhone__c', objIndependentServicerWrapper.ContactPhone);
jsonGenerator.writeObjectField('ContactPhoneExtension__c', nfm_Utils.IfNull(objIndependentServicerWrapper.ContactPhoneExtension,''));
}
String jsonBody = '\'' + jsonGenerator.getAsString() + '\'';
String jsonResult = nfm_FurnitureServicesCallout.upsertFurnitureServicesCallout(jsonBody);
String result = '';
if(!Test.isRunningTest()){
Map<String, Object> jsonResultMap = (Map<String, Object>) JSON.deserializeUntyped(jsonResult);
String[] furnitureServicesFieldsList = new List<String>{ 'ExternalId','Id','AppointmentUnits__c','InspectAddress1__c','InspectName__c','InspectDate__c' };
Map<String,String> furnitureServicesFieldValueMap = new Map<String,String>();
furnitureServicesFieldValueMap.put('ClaimId__c', String.valueOf(jsonResultMap.get('ClaimId')));
FurnitureServices__x objFurnitureServices = nfm_ExternalFurnitureServicesRequest.getFurnitureServices(furnitureServicesFieldsList, furnitureServicesFieldValueMap, 'Id', 'ASC')[0];
UserActivityController.createRecord(objScheduleServiceWrapper.ButtonLabel, 'Claim', objScheduleServiceWrapper.ClaimId);
if(isIndependentServicer){
updateServiceAssignedDate(objIndependentServicerWrapper.CaseId, Date.newInstance(Integer.valueOf(inspectDateYear), Integer.valueOf(inspectDateMonth), Integer.valueOf(inspectDateDay)));
}
return objFurnitureServices.Id;
} else {
result = 'ok';
}
return result;
}
public static FurnitureServices__x getPreviousFurnitureService(String claimId){
Map<String,String> furnitureServicesFieldValueMap = new Map<String,String>();
furnitureServicesFieldValueMap.put('ClaimId__c', claimId);
return nfm_ExternalFurnitureServicesRequest.getFurnitureServices(SObjectUtils.getAllFieldsAPINames('FurnitureServices__x'), furnitureServicesFieldValueMap, 'Id', 'ASC')[0];
}
#AuraEnabled
public static List<FurnitureServiceRoutes__x> getFurnitureServiceRoutes(String startDate,String numberOfDays,String zipCode){
String[] furnitureServiceRoutesFieldsList = new List<String>{
'Id', 'NumberOfDays__c', 'RouteCode__c', 'RouteDescription__c', 'ServiceCode__c', 'StartDate__c', 'ZipCode__c'
};
Map<String,String> furnitureServiceRoutesFieldValueMap = new Map<String,String>();
furnitureServiceRoutesFieldValueMap.put('NumberOfDays__c',numberOfDays);
furnitureServiceRoutesFieldValueMap.put('StartDate__c',startDate);
furnitureServiceRoutesFieldValueMap.put('ZipCode__c',zipCode);
return nfm_ExternalFurnitureServiceRoutesReq.getFurnitureServiceRoutes(furnitureServiceRoutesFieldsList, furnitureServiceRoutesFieldValueMap, 'RouteCode__c', 'ASC');
}
#AuraEnabled
public static List<FurnitureServiceAppointments__x> getFurnitureServiceAppointments(String startDate,String numberOfDays,String zipCode, String routeCode){
String[] furnitureServiceAppointmentsFieldsList = new List<String>{
'Id', 'AppointmentUnits__c', 'ServiceDate__c', 'StartDate__c', 'ZipCode__c','RouteCode__c'
};
Map<String,String> furnitureServiceAppointmentsFieldValueMap = new Map<String,String>();
furnitureServiceAppointmentsFieldValueMap.put('NumberOfDays__c',numberOfDays);
furnitureServiceAppointmentsFieldValueMap.put('StartDate__c',startDate);
furnitureServiceAppointmentsFieldValueMap.put('ZipCode__c',zipCode);
furnitureServiceAppointmentsFieldValueMap.put('RouteCode__c',routeCode);
return nfm_ExternalFurnitureServiceAppRequest.getFurnitureServiceAppointments(furnitureServiceAppointmentsFieldsList, furnitureServiceAppointmentsFieldValueMap, 'RouteCode__c', 'ASC');
}
#AuraEnabled
public static Boolean hasAccessToIndependentServicerPermset(){
Id userId = UserInfo.getUserId();
String permsetApiName = 'Custom_Contact_Center_Support_Team';
return nfm_Utils.isPermsetAssignedToUser(userId, permsetApiName);
}
**#AuraEnabled
public static Case retrieveCaseObject(Id caseId){
return [
SELECT
Id, Shipping_Address_1__c, Shipping_Address_2__c, Shipping_City__c, Shipping_State__c,
Shipping_Postal_Code__c, Call_Back_Contact__c, Requested_Call_Back_Number__c,
Requested_Call_Back_Number_Ext__c ,Independent_Servicer__r.Id, Independent_Servicer__r.Servicer_Id__c, Independent_Servicer__r.Name
FROM Case
WHERE Id = :caseId
LIMIT 1
];
}**
public static void updateServiceAssignedDate(Id caseId, date newDate){
Case objCase = [SELECT Id, Service_Assigned_Date__c FROM Case WHERE Id = :caseId LIMIT 1];
objCase.Service_Assigned_Date__c = newDate;
update objCase;
}
}
method to fetch case record
fetchCaseData : function(component, event, helper) {
var caseRecord = component.get('v.caseRecord');
var newCaseId = caseRecord.recordId;
var retrieveCaseAction = component.get('c.retrieveCaseObject');
var actionParams = {'caseId':newCaseId};
retrieveCaseAction.setParams(actionParams);
retrieveCaseAction.setCallback(this, function(response) {
var state = response.getState();
if (state === "SUCCESS") {
var result = response.getReturnValue();
//console.log('RESULT: ' + JSON.stringify(result));
var currentCaseRecord = component.get('v.caseRecord');
result.label = currentCaseRecord.label;
result.recordId = currentCaseRecord.recordId;
component.set('v.caseRecord', result);
component.set('v.isLoading', false);
} else {
console.log(response.getError());
}
});
$A.enqueueAction(retrieveCaseAction);
},
when clicked on reschedule spinner should not spin continuously
enter image description here
enter image description here
should be able to reschedule
Needs more info (but too long for comment).
Which JS function is called when that button (quick action?) is clicked? It doesn't look like you followed the customary {!c.doInit} naming convention.
You pasted a lot of code, servicer_id__c appears in 3 places. Next time try to cut the useless pieces until you're left with Minimal Reproducible Example.
Check Apex Developer Console for errors / problems, maybe one of the functions genuinely returns null / throws error:
lack of permissions to run this apex class
really bad data (Case without some lookup populated?)
maybe you carefully created a wrapper class to hold stuff returned from apex - but you forgot to mark every field as public and #AuraEnabled
I suspect the bad code is around places like caseRecord.Independent_Servicer__r.Servicer_Id__c in isIndependentServicerCheckedChanged. You don't check if the middle part is null. A ternary operator or optional chaining could make it easier to spot.
Enable Setup -> Debug mode (if not done already) and next time just click that error logged in JavaScript console. You'll be taken to the line in source code where it happened. It won't look exactly like your source code (SF transpiles a bit and merges multiple files into 1) but it should be close enough for you to recognise and fix the mistake. Or at least put some breakpoints / watches.
I have a stored proc like this:
CREATE PROCEDURE [dbo].[Organisation_Insert]
#OrganisationXId uniqueidentifier
,#Enabled bit
,#Timezone nvarchar(50)
,#MinimumValue float
,#Rules ReminderRuleType READONLY ...
ReminderRuleType is a user defined type.
In my app I have this:
class OrganisationDTO
{
private readonly IOrganisationDocument _orgDoc;
public long OrganisationId { get { return _orgDoc.OrganisationId; } }
public Guid OrganisationXId { get { return _orgDoc.OrganisationXId; } }
public string TimeZone { get { return _orgDoc.TimeZone; } }
public bool Enabled { get { return _orgDoc.Enabled; } }
public decimal MinimumValue { get { return _orgDoc.MinimumValue; } }
public RuleTableValuedParameters Rules { get; private set; }
public OrganisationDTO(IOrganisationDocument orgDoc)
{
_orgDoc = orgDoc;
Rules = new RuleTableValuedParameters("#Rules", _orgDoc.Rules);
}
}
RuleTableValuedParameters implements SqlMapper.IDynamicParameters which has an AddParameters method.
When I execute the query, the #Rules parameter is never passed (using SQLProfiler). I can also see that AddParameters is never called.
Is this possible to do?
Thanks
Here's a simplified example based on your code that shows it working just fine; AddParameters is invoked correctly, and the values are conveyed to the stored procedure. As a side note: if you are using DataTable for your TVPs, the library supports that directly with no additional code needed.
public void SO29596645_TvpProperty()
{
try { connection.Execute("CREATE TYPE SO29596645_ReminderRuleType AS TABLE (id int NOT NULL)"); }
catch { }
connection.Execute(#"create proc #SO29596645_Proc (#Id int, #Rules SO29596645_ReminderRuleType READONLY)
as begin select #Id + ISNULL((select sum(id) from #Rules), 0); end");
var obj = new SO29596645_OrganisationDTO();
int val = connection.Query<int>("#SO29596645_Proc", obj.Rules, commandType: CommandType.StoredProcedure).Single();
// 4 + 9 + 7 = 20
val.IsEqualTo(20);
}
class SO29596645_RuleTableValuedParameters : Dapper.SqlMapper.IDynamicParameters {
private string parameterName;
public SO29596645_RuleTableValuedParameters(string parameterName)
{
this.parameterName = parameterName;
}
public void AddParameters(IDbCommand command, Dapper.SqlMapper.Identity identity)
{
Console.WriteLine("> AddParameters");
SqlCommand lazy = (SqlCommand)command;
lazy.Parameters.AddWithValue("Id", 7);
DataTable table = new DataTable {
Columns = {{"Id", typeof(int)}},
Rows = {{4}, {9}}
};
lazy.Parameters.AddWithValue("Rules", table);
Console.WriteLine("< AddParameters");
}
}
class SO29596645_OrganisationDTO
{
public SO29596645_RuleTableValuedParameters Rules { get; private set; }
public SO29596645_OrganisationDTO()
{
Rules = new SO29596645_RuleTableValuedParameters("#Rules");
}
}
Here's the full working DynamicParameter that I created:
public class OrganisationDynamicParameter : SqlMapper.IDynamicParameters
{
private readonly IOrganisation _orgModel;
public OrganisationDynamicParameter(IOrganisation orgModel)
{
_orgModel = orgModel;
}
public void AddParameters(IDbCommand command, SqlMapper.Identity identity)
{
SqlParameter p;
var sqlCommand = (SqlCommand)command;
sqlCommand.CommandType = CommandType.StoredProcedure;
p = sqlCommand.Parameters.Add("#OrganisationXId", SqlDbType.UniqueIdentifier);
p.Value = _orgModel.OrganisationXId;
p = sqlCommand.Parameters.Add("#Enabled", SqlDbType.Bit);
p.Value = _orgModel.Enabled;
p = sqlCommand.Parameters.Add("#Timezone", SqlDbType.NVarChar, 50);
p.Value = _orgModel.TimeZone;
p = sqlCommand.Parameters.Add("#MinimumValue", SqlDbType.Float);
p.Value = _orgModel.MinimumValue;
List<SqlDataRecord> ruleList = _orgModel.Rules.Select(MapRuleData).ToList();
if (ruleList.Count > 0)
{
p = sqlCommand.Parameters.Add("#Rules", SqlDbType.Structured);
p.Direction = ParameterDirection.Input;
p.TypeName = "ReminderRuleType";
p.Value = ruleList;
}
}
protected SqlDataRecord MapRuleData(IReminderRule value)
{
var rec = new SqlDataRecord(new[]
{
new SqlMetaData("RuleId", SqlDbType.BigInt),
new SqlMetaData("OrganisationId", SqlDbType.BigInt),
new SqlMetaData("Name", SqlDbType.NVarChar, 200),
new SqlMetaData("OffsetDays", SqlDbType.Int),
new SqlMetaData("SubjectTemplate", SqlDbType.NVarChar, -1),
new SqlMetaData("BodyTemplate", SqlDbType.NVarChar, -1)
});
rec.SetInt64(0, value.RuleId);
rec.SetInt64(1, value.OrganisationId);
rec.SetString(2, value.Name);
rec.SetInt32(3, value.OffsetDays);
rec.SetString(4, value.SubjectTemplate);
rec.SetString(5, value.BodyTemplate);
return rec;
}
}
I use this thusly:
public IOrganisation CreateOrganisation(IOrganisation organisation)
{
var dtoOrg = new OrganisationDynamicParameter(organisation);
return ExecuteSPReturningOrganisation("Organisation_Insert", dtoOrg);
}
protected IOrganisation ExecuteSPReturningOrganisation(string query, object parameters)
{
using (IDbConnection con = ConnectionFactory.CreateOpenConnection())
{
using (
SqlMapper.GridReader multi = con.QueryMultiple(query, parameters,
commandType: CommandType.StoredProcedure))
{
OrganisationModel org = multi.Read<OrganisationModel>().SingleOrDefault();
if (org != null)
{
org.Rules = multi.Read<ReminderRuleModel>().ToArray();
}
return org;
}
}
}
Cheers