Extension Tips and Tricks
This page contains tips and tricks, methods, and workarounds to common issues in extensions, and error handling methods with the use of examples.
- Debug
- Return a value from application
- Exception Handling
- Feature
- Get from Input
- Set to Input
- Set to Label
- Fill Input’s List
- Input Visibility
- Input Status
- Input Validation
- Listen Button
- Tips
- New or Saved Record
- Keep Inputs Values
- Application’s Tab Number
- Application’s Record ID
- Trigger Workbook Calculation By Specific Input
Debug
Make sure to set Debug tag to tru****e in config file
Return a value from application
To return a message or value via a message box, return a string with your info:
ret += "\n " + "your message";
Exception Handling
To return a message or value via a message box, return a string with your info:
try {
} catch (Exception exc) { ret += "\n " + exc.Message; }
Feature
Get from Input
Get value from input. “PSWInput_0_0” is input’s name, assigned by SSWEB Wizard.
string inp_0_0 = inputs_["PSWInput_0_0"];
Set to Input
Set value to input:
var result = 0; outputs_ = new Dictionary>(); outputs_.Add("PSWInput_0_2", new Dictionary { { "value", result.ToString() } });
Set to Label
Set value to label. “PSWTab_0.Label_1_4” means: Label at 1st(0) tab, 1st(1) column, 4th(4) row.
var result = 0; outputs_ = new Dictionary>(); outputs_.Add("PSWTab_0.Label_1_4", new Dictionary { { "text", result.ToString() } });
Fill Input’s List
Fill list of a combobox or listbox:
List items should be in a single string variable and separated by a colon (:). Eg.
"ALEUTIANS EAST:ALEUTIANS WEST:ANCHORAGE" string has 3 items.
var string AK = "ALEUTIANS EAST:ALEUTIANS WEST:ANCHORAGE"; outputs_ = new Dictionary>(); outputs_.Add("PSWInput_0_1", new Dictionary { { "populate", AK } });
Input Visibility
Make inputs visible or hidden to create a dynamic user interface.
The property “visible”, should also be enabled with SpreadsheetWeb Wizard.
outputs_.Add("PSWInput_1_17", new Dictionary { { "visible", "true" } }); //visible outputs_.Add("PSWInput_1_17", new Dictionary { { "visible", "false" } }); // NOT visible
Input Status
For only showing the inputs to your users; use the “enable” property. Users can’t edit the inputs.
Enable property should also be enabled by SpreadsheetWeb Wizard.
outputs_.Add("PSWInput_1_17", new Dictionary { { "enable", "true" } }); //enable outputs_.Add("PSWInput_1_17", new Dictionary { { "enable", "false" } }); //disable
Input Validation
Limit your input’s values, depending on other variables by dynamic validation rules.
Validation property should also be enabled by the SpreadsheetWeb Wizard.
//Only dates can be entered are between 1/1/2015 and 1/1/2016 string date = "1/1/2015"; string SecVal = "1/1/2016"; outputs_.Add("PSWInput_1_1", new Dictionary { { "validation_value1", date }, {"validation_value2", SecVal }, { "validation_message", "Effective Date must be between: " + date + " and " + SecVal } });
Listen Button
Check if specific button is clicked. “btn_0_Next_0”: 1st(0) tab, Next(Next) button, 1st(0) button.
if (sender_ == "btn_0_Next_0") //Next
Tips
New or Saved Record
Check if the app is running an existing record. queryStrings_[“Action”] returns the application’s state.
bool isExistingRecord = queryStrings_.ContainsKey("Action") && (queryStrings_["Action"] == "Edit");
Keep Inputs Values
To keep the current values of the inputs, get and set all the inputs.
Getting and re-setting all inputs operation might be mandatory for some extension codes. If your inputs return their defaults, please use this code to block the end of your code.
foreach (var inp in inputs_) { var vStr = inp.Value; if (outputs_.ContainsKey(inp.Key)) { if (!outputs_[inp.Key].ContainsKey("value")) outputs_[inp.Key].Add("value", vStr); } else { p = new Dictionary(); p.Add("value", vStr); outputs_.Add(inp.Key, p); } }
Application’s Tab Number
To check which tab the user is at;
var tabIndex_ = int.Parse(queryStrings_["TabIndex"]); if (tabIndex == 2 && !tabLoaded.ContainsKey(2))
Application’s Record ID
You can check which saved record is running. Be note that new records are always -1.
string recID = queryStrings_["RecordId"];
Trigger Workbook Calculation By Specific Input
When you need the power of Excel to calculate complex equations, you should calculate whole application. However; a full calculation process can take a long time, depending on the complexity of your document. If you want to control whenever a full calculation is triggered, you can use this code:
//Use Value_Changed to listen your inputs public string Value_Changed(string vjsClientId_, string sender_, Dictionary queryStrings_, ref Dictionary inputs_, out Dictionary> outputs_, out bool executeSSWeb) { var ret = ""; outputs_ = new Dictionary>(); string inp_0_5 = inputs_["PSWInput_0_5"]; if (inp_0_5 != "(Select Value)") executeSSWeb = true; //calculate only when PSWInput_0_5 has a different value than "(Select Value)" else executeSSWeb = false; //NOT calculate for other inputs foreach (string current in inputs_.Keys) { outputs_.Add(current, new Dictionary { { "value", inputs_[current] } }); } return ret; }
