0

I feel like I've tried everything, but I keep coming up short. I am working on a course in Storyline 360, and I am able to return statements just fine when using verbs and object IDs, but no matter what I do to try and return statements for a specific Agent, I cannot get a query to go through.

Here's my code as it stands now - where I do return plenty of statements...what I need to know is how to have it query the current learner's statements for matches. I'm able to pull in their name or mbox, but trying to pass those through in my params fails on me every time.

Any help is very much appreciated!

var lrs;
var statementFound = false;
var player = GetPlayer();
try {
    lrs = new TinCan.LRS(
        {
            endpoint: "https://cloud.scorm.com/lrs/MYINFO/",
            username: "MYINFO",
            password: "MYINFO",
            allowFail: false
        }
    );
}
catch (ex) {
    console.log("Failed to setup LRS object: ", ex);
    // TODO: do something with error, can't communicate with LRS
};

var myObj = JSON.parse(getParameterByName('actor'));
lrs.queryStatements(
    {
        params: {
            verb: new TinCan.Verb(
                { 
                   id:  "http://adlnet.gov/expapi/verbs/answered"
                }
            )
    },
        callback: function (err, sr) {
            if (err !== null) {
                console.log("Failed to query statements: " + err);
                // TODO: do something with error, didn't get statements
                return;
             }

            if (sr.more !== null) {
                // TODO: additional page(s) of statements should be fetched
             }

           if (sr.statements.length > 0) {
            statementFound = true;
             console.log(sr.statements);
             player.SetVar("sf",statementFound);
            }
        }
    }
);

var myObj is able to pull in the necessary info to ID the learner if needed - but again, I just can't figure out how to get it passed in the query.

dogtuna
  • 3
  • 1

1 Answers1

1

You need to set an agent property in the params object passed in the first argument. Assuming the Agent is the actor in statements.

lrs.queryStatements(
    {
        params: {
            agent: TinCan.Agent.fromJSON(getParameterByName('actor'))
        }
    },
    ...
);
Brian J. Miller
  • 2,169
  • 1
  • 12
  • 12
  • Brian. You may have just changed my life, my man. I have been fighting with this for a couple of days, and I was so close to giving up. I had never even tried TinCan.Agent.fromJSON - this makes so much more sense, and I cannot tell you how you've turned my day around! Thank you thank you thank you. – dogtuna Jun 25 '20 at 21:33
  • The solution above works great for my initial situation - but let's say I want to hard code a name into that query - what would that look like? – dogtuna Jun 26 '20 at 21:44
  • Any `TinCan.Agent` object can be passed as the value of that parameter, so however you construct said instance will work. You can just do `new TinCan.Agent({"mbox": "..."})` or any other IFI allowed by the xAPI spec. The `fromJSON` method is an easy "factory" method to have the library parse a string of JSON and construct the object all at once. – Brian J. Miller Jun 27 '20 at 18:11
  • Thank you again - these two pieces of help are huge for what I needed. Can't thank you enough. – dogtuna Jun 27 '20 at 18:45