cancel
Showing results for 
Search instead for 
Did you mean: 

MDK - Convert Value of Segemented Control to "true/false" on OData Action

jamesw_
Explorer
0 Kudos
422

HI,

I have a segmented control with 2 values ("Partial" and "Final"). When clicking "Submit" on the page it does a CallFunction OData Action and sends data back to SAP. The CallFunction Action contains two parameters of "Partial" and "Final" which need to be either "true" or "false".

How do I say "if Partial is selected, then set Partial Flag on CallFunction Action to true" (same for Final)?


...{
                            "_Type": "Control.Type.FormCell.SegmentedControl",
                            "_Name": "FormCellSegmentedControl0",
                            "IsEditable": true,
                            "IsVisible": true,
                            "Caption": "Type",
                            "ApportionsSegmentWidthsByContent": false,
                            "Segments": [
                               "Final",
                               "Partial"
                            ]
}...

Action:

..."Function": {
			"Name": "Confirmation",
			"Parameters": {
				"Final": false, <-- I want this to be "if Final is selected, then true"
...

Thanks,

James

Accepted Solutions (0)

Answers (1)

Answers (1)

bill_froelich
Product and Topic Expert
Product and Topic Expert
0 Kudos

Assign a rule to the Final property in your CallFunction action. In the rule get the return value from the Segmented control and based on the value return true or false from your rule.

jamesw_
Explorer
0 Kudos

Hi,

So I did the following:

export default function CheckFinalFlag(context) {
    if ((context.evaluateTargetPath('#Control:FCType/#Value')) === "Final") {
        return true;
    }
    
    return false;
}

.. and have this in the Function Import call, which is saying "expected boolean":

bill_froelich
Product and Topic Expert
Product and Topic Expert
0 Kudos

It is probable that the validation error is a false positive where the validator is not detecting the value as a rule and ignoring it but rather validating that it is either a literal true or false string for the property.

I would go ahead and deploy it with the rule and test. I expect it will work correctly (assuming your rule is correct). In which case let us know and we can open a issue for the editor to enhance the validation check.

jamesw_
Explorer

Hi Bill,

The backend still shows blank values for Final and Partial:

Is this because the values are held in a Segmented controls, and so #value has no meaning here? If so, how would I get the "selected value" (#SelectedValue??)?

EDIT: Yes, it was that. Fixed with this rule:

/**
 * Describe this function...
 * @param {IClientAPI} context
 */
 export default function CheckFinalFlag(context) {
    let oSegControl = context.evaluateTargetPath('#Page:Operation_Confirmation/#Control:FCType');

    if ((oSegControl.getValue()[0].ReturnValue) === "Final") {
        return true;
    }
    
    return false;
}