skelta.grid.saveGridDataToCloudStorage()
- Last UpdatedJun 25, 2024
- 3 minute read
Use skelta.grid.saveGridDataToCloudStorage method to get the Grid control contents, export it into Excel, upload the Excel File to the AVEVA Cloud Storage and return the filename. This filename can be stored in the Forms Control and passed to the workflow used in the Ingestion Activity.
Note:
- To extract data to Excel from the Grid control, set the Export All Pages property to Yes in the Grid control.
- This API should not be used in OnFormLoad script as the Grid data would not have
been loaded during the Form load. This is an asynchronous API, so it should be used
appropriately.
- In case the Form has Desktop View Only and Delay the Loading of Containers properties configured as Yes, the Grid data will be loaded only when the container is accessed. For example, a
Grid control is present inside the second Tab of the Tabs control, the Grid data would only get loaded when the second Tab is accessed. In such instances of Grid controls, the API gives validation messages.
Syntax
skelta.grid.saveGridDataToCloudStorage(sources, ignoreEmptyGridDataValidation)
Parameters
-
sources (Array type parameter)
This is an array object representing gridObject and fileName for the Grid.
Example 1: Consider a form with a Grid Control named InvoiceGrid. The parameter should be like,
var sources=[{"gridObject":control.findByXmlNode("InvoiceGrid"), "fileName":"InvoiceDet.Xlsx"}]
InvoiceGrid is the Grid control used in the form specified in the gridObject parameter.
InvoiceDet.Xlsx is the filename to be used for uploading the data extracted from the gridObject to the AVEVA Cloud Storage.
Example 2: Consider a form with multiple Tab controls and Grid controls within each Tab. Then, the parameter should be like,
var sources=[{"gridObject":control.findByXmlNode("OrderDetailsGrid"), "fileName":"OrderDet.Xlsx"}, {"gridObject":control.findByXmlNode("CustomerDetailsGrid"), "fileName":"CustDet.xlsx"}];
OrderDetailsGrid and CustomerDetailsGrid are the Grid controls used in the form specified in the gridObject parameter.
OrderDet.Xlsx and CustDet.xlsx are the filenames to be used for uploading the data extracted from the gridObject to the AVEVA Cloud Storage.
-
ignoreEmptyGridDataValidation (Boolean type parameter)
This parameter is to indicate what to do if the data is empty for the specified Grid Object.
By default, the value of the parameter is false. If the data is empty in the GridObject, the user will get a validation message that Grid Data is empty.
If the value of the parameter is true, the returned filename will be empty and user will not get any validation message.
Return Value
This method returns an array of string value(s).
Example
Below is a sample for uploading the three Grid Object data in excel format to AVEVA Cloud Storage and to store the returned filename in the Target Control text boxes (HiddenField controls can also be used), which can be used in the workflow.
// Preparing the sources parameter for the API
var sources=[{"gridObject":control.findByXmlNode("InvoiceGrid"), "fileName":" InvoiceGridData.XlSx"},
{"gridObject":control.findByXmlNode("OrderDetailsGrid"), "fileName":" OrderDetailsGridData.XlSx"},
{"gridObject":control.findByXmlNode("CustomerDetailsGrid"),"fileName":" CustomerDetailsGridData.XlSx"}];
// Below array to map the respective sources with the target controls to store the returned file names from the AVEVA Cloud Storage
var targetControl=[control.findByXmlNode("ExportedFileName1"), control.findByXmlNode("ExportedFileName2"), control.findByXmlNode("ExportedFileName3")];
// To consider the empty grid data or not
var ignoreEmptyGridDataValidation = false;
// Show the Loader before calling the API
SFU.showLoader();
// API call to perform the extraction of grid data from the sources and upload to AVEVA Cloud Storage
skelta.grid.saveGridDataToCloudStorage(sources, ignoreEmptyGridDataValidation)
.then(function(results){
var errorMessages="";
$.each(results,function(index,item)
{
if(SFU.isUndefined(item.fileName) || item.fileName=="")
{
if(!SFU.isUndefined( item.error))
{
if(errorMessages.length>0)
{
errorMessages += "<br>";
}
errorMessages += item.error.replaceString("\n","<br>");
}
else
{
targetControl[index].value="";
}
}
else
{
targetControl[index].value=item.fileName;
}
});
if(errorMessages.length>0)
{
SFU.hideLoader();
SFU.showError(document.title, errorMessages);
}
else
{
// Since we are submitting the form, we need not hide the loader
control.submitForm(event);
}
});