Your achievements

Level 1

0% to

Level 2

Tip /
Sign in

Sign in to Community

to gain points, level up, and earn exciting badges like the new
BedrockMission!

Learn More

View all

Sign in to view all badges

Getting variables out of a function

Avatar

Avatar
Validate 1
Level 10
Niall_O_Donovan
Level 10

Likes

646 likes

Total Posts

4,352 posts

Correct Reply

786 solutions
Top badges earned
Validate 1
Boost 500
Boost 50
Boost 5
Boost 3
View profile

Avatar
Validate 1
Level 10
Niall_O_Donovan
Level 10

Likes

646 likes

Total Posts

4,352 posts

Correct Reply

786 solutions
Top badges earned
Validate 1
Boost 500
Boost 50
Boost 5
Boost 3
View profile
Niall_O_Donovan
Level 10

29-04-2009

Hi,

In order to reduce the use of the calculation event in a repeating subform, I have set up a function (riskRating) in a script object (calculateRisk), which the exit event of a dropdown (RA_severity) calls.

//This is the Javascript in the exit event...

var vLikelihood = RA_likelihood.rawValue; //dropdown list 1
var vSeverity = RA_severity.rawValue; //dropdown list 2
var vRisk;

calculateRisk.riskRating(vLikelihood, vSeverity);

console.println("Risk after function = " + vRisk);

RA_risk_rating.rawValue = vRisk;  //this line is meant to assign the value of vRisk from the function to another field (but it doesn't)

//This is the function within calculateRisk script object...

function riskRating(vLikelihood, vSeverity)
{  

    var vRisk;

    if (vLikelihood == null && vSeverity == null)
    {
        vRisk = null;
    }

    else
    {
        vRisk = vLikelihood * vSeverity;
    }
   
    console.println("Risk inside function = " + vRisk);
   
    return vRisk;
   
}

I have tried various approaches to get the answer back out of the function and to be used for the remainder of the script in the exit event script.

The console show the correct calculation in the function, but it is not updating the variable outside of the function.

Any ideas?

Thanks,

Niall

View Entire Topic

Avatar

Avatar
Validate 1
Level 9
Steve_L_Walker
Level 9

Likes

197 likes

Total Posts

1,435 posts

Correct Reply

212 solutions
Top badges earned
Validate 1
Boost 50
Boost 5
Boost 3
Boost 25
View profile

Avatar
Validate 1
Level 9
Steve_L_Walker
Level 9

Likes

197 likes

Total Posts

1,435 posts

Correct Reply

212 solutions
Top badges earned
Validate 1
Boost 50
Boost 5
Boost 3
Boost 25
View profile
Steve_L_Walker
Level 9

29-04-2009

Niall,

Take a look at the attached. The form contains four numeric fields: 'a', 'b', 'total', and 'other'. It does a calculate on fields 'a' and 'b'. On the exit event of 'b' it calls 'addNumbers()' in 'MyScriptObject'. The function updates 'total' and returns the value of 'total' to be bound to 'other'.

// form1.page1.subform1.b::exit - (JavaScript, client)

other.rawValue = MyScriptObject.addNumbers(a,b,total);

// form1.#variables[0].MyScriptObject - (JavaScript, client)

function addNumbers(a_,b_,total_) {
    return(total_.rawValue = a_.rawValue + b_.rawValue);
}

Is that what you are looking for?

Steve