Overview

In this article, we’ll go over how to use the power functionality when writing your skills in the IDE.

 

In this Article

 

What is a Power?

A Power is a built-in function that you can use to help you write your skills. Most powers will return a promise.

 

When to use a Power

When defining your variables or return statements to perform a common task, you should see if an applicable power is available to simplify your code.

 

How to Call a Power

Use IntelliSense throughout each step to choose from available options or refer to the Andi® Powers documentation in the Skill Manager. The following contains an example of one of many available powers.

To reveal available powers, use the skillContext powers property:

skillContext.powers.

Then, you’ll select the source of the power.

skillContext.powers.precisionLender.

Then, you’ll select the power context.

skillContext.powers.precisionLender.opportunity.

Then, you’ll select the method, which contains the function you will use.

skillContext.powers.precisionLender.opportunity.isOpportunityChangeEvent();

 

Powers and Async/Await

Because most powers return a promise, you can use the Async/Await pattern to allow for any calls that are returning a promise to be awaited on without needing to call .then(), making your code appear synchronous.

For example:

export async function shouldIRun(skillContext:andiSkills.ISkillContext): Promise {
    const event: andiSkills.IApplicationEvent = skillContext.event as andiSkills.IApplicationEvent;
    const shouldIRunPower: any = skillContext.powers.andi.shouldIRun;
    const opportunityPower: any = skillContext.powers.precisionLender.opportunity;
    
    if (event.applicationEventName && event.applicationEventName.indexOf("scenarioRecalculated") > -1) {
        const opportunityModel: OpportunityModel
            = await opportunityPower.getCurrentOpportunityModel();
        if (!opportunityModel) { throw new Error("Missing opportunityModel"); }

        const commercialLoanAccounts: CommercialLoanAccount[] = opportunityModel.engineModel.commercialLoanAccounts;
        if (!commercialLoanAccounts) { throw new Error("Missing commercialLoanAccounts"); }

        const currentlyViewContext: any = skillContext.event
            .currentlyViewedContext.find((context) => {
                return context["name"] &&
                    context["name"] === "commercialLoanAccount" &&
                    context["selectedTab"] &&
                    context["selectedTab"] === true;
            });
        if (!currentlyViewContext) { throw new Error("Missing currentlyViewContext"); }

        const currentCommercialLoanAccount: CommercialLoanAccount = 
            commercialLoanAccounts.find((commercialLoan) => {
                return commercialLoan.id === currentlyViewContext.id; 
            });
        if (!currentCommercialLoanAccount) {
            throw new Error("Missing currentCommercialLoadAccount");
        }
        await (skillContext).setSkillRunState("currentLoan", currentCommercialLoanAccount);
        return shouldIRunPower.shouldIRunTrue();
    }
    return shouldIRunPower.shouldIRunFalse();
}
Was this article helpful?
3 out of 3 found this helpful