private callCustomAPI= async () =>{
// Prepare the input parameter as a JSON string
const inputParamValue = {
new_customAPI_TifBase64FileParam: [this.state.fileContent], // String array for Base64 encoded file
new_customAPI_RollTypeParam: this.state.rollType,
new_customAPI_RollYearParam: this.state.rollYear,
new_customAPI_RollNumberParam: this.state.rollNum
};
try {
console.log('Calling custom action with input:', inputParamValue);
console.log('DEGUG PROPS CONTEXT: ', this.props.context);
// Prepare the API request with the correct metadata and parameters
const apiRequest = {
getMetadata: () => ({
operationType: 0, // Operation type (0 for action)
operationName: "new_customAPI", // Custom API action name
parameterTypes: {
new_customAPI_TifBase64FileParam: {
typeName: "Collection(Edm.String)", // Define the array of strings (Base64 encoded file)
structuralProperty: 4
},
new_customAPI_RollTypeParam: {
typeName: "Edm.String", // Define string parameter
structuralProperty: 1
},
new_customAPI_RollYearParam: {
typeName: "Edm.String", // Define string parameter
structuralProperty: 1
},
new_customAPI_RollNumberParam: {
typeName: "Edm.String", // Define string parameter
structuralProperty: 1
}
}
}),
new_customAPI_TifBase64FileParam: inputParamValue.new_customAPI_TifBase64FileParam,
new_customAPI_RollTypeParam: inputParamValue.new_customAPI_RollTypeParam,
new_customAPI_RollYearParam: inputParamValue.new_customAPI_RollYearParam,
new_customAPI_RollNumberParam: inputParamValue.new_customAPI_RollNumberParam
};
// Log for debugging
console.log(`Calling custom action 'new_customAPI' with Input Parameter: ${JSON.stringify(inputParamValue)}`);
// ts-expect-error Suppressing type error due to custom Web API call
const response = await this.context.webAPI.execute(apiRequest);
// const response = await this.props.context.webAPI.execute(apiRequest); // const response = await this.props.context.webAPI.createRecord(apiRequest);
const jsonResponse = await response.json();
console.log(`Custom action response: ${JSON.stringify(jsonResponse)}`);
// Extract and return the output value from the response if needed
const result = jsonResponse.result || "";
if (result) {
alert('File passed successfully!');
} else {
alert('Error occurred during the file pass through custom API.');
}
} catch (error) {
console.error('Error calling custom action: ', error);
alert('An error occurred while passing the file.');
throw error;
}
}