cancel
Showing results for 
Search instead for 
Did you mean: 

How to call SAP MDK Rule/Actions from Extension nativescript control (.ts file)?

itsumerfarooq
Participant

Hi Experts,

We have created an Extension Control that contains a Link. We want to navigate to another SAP MDK Page by calling an SAP MDK Action or Rule but not able to do so. We were trying to get the ClientAPI reference in nativescript ts file but no luck so far. Please suggest?

jitendra.kansal bill.froelich Appreciate if experts like you people can help us sort it out this issue.

Jitendra_Kansal
Product and Topic Expert
Product and Topic Expert
itsumerfarooq

Could you please share how you are attempting to call the MDK Action/rule within your extension?

itsumerfarooq
Participant
0 Kudos

Hi Jitendra,

Thank you for the reply.

We are trying the following way to create an extension component that includes both Text and Link.

We want to execute the "/MyDemoApp/Actions/NavToVerCode.action" on link click

const mainText = "Have an account?";
const textPart1 = "Sign In";
const linkPart1 = "/MyDemoApp/Actions/NavToVerCode.action";


const fullText = `${mainText} ${textPart1}`;

const startIndex = fullText.indexOf(textPart1);
const endIndex = startIndex + textPart1.length;
const textColorBlack = android.graphics.Color.BLACK;
// Create a SpannableString for the full text
const spannableFullText = new android.text.SpannableString(fullText);
const urlSpan = new android.text.style.URLSpan(linkPart1);
spannableFullText.setSpan(urlSpan, startIndex, endIndex, android.text.Spanned.SPAN_INCLUSIVE_INCLUSIVE);
spannableFullText.setSpan(new android.text.style.ForegroundColorSpan(textColor), startIndex, endIndex, android.text.Spanned.SPAN_INCLUSIVE_INCLUSIVE);
spannableFullText.setSpan(new android.text.style.ForegroundColorSpan(textColorBlack), 0, mainText.length, android.text.Spanned.SPAN_INCLUSIVE_INCLUSIVE);


// Set the SpannableString as the text for the TextView
this._text.setText(spannableFullText);

// Enable click event on the TextView
this._text.setMovementMethod(android.text.method.LinkMovementMethod.getInstance());
View Entire Topic
mingkho
Advisor
Advisor

Hi Umer

Your extension class should be extending IView or IControl or BaseControl, and they have a function called executeActionOrRule that you can call. It accept path to an action or rule and return a promise that'll be resolved when the action or rule completed (or rejected when they failed).

https://help.sap.com/doc/3642933ef2e1478fb1578ef2acba4ae9/Latest/en-US/reference/apidoc/classes/ivie...

e.g. (Here I am assuming 'this' object is your extension class which extend IView or IControl or BaseControl):

this.executeActionOrRule("/MyDemoApp/Actions/NavToVerCode.action").then(() => {
  // Do something here for success, if needed.
}).catch((err) => {
  // Do something for the error, if needed.
});

Regards

Ming

itsumerfarooq
Participant
0 Kudos

Thank you! It worked.