cancel
Showing results for 
Search instead for 
Did you mean: 
j_causby
Community Member

LTI Variable Replacement as part of a custom field

Hello Devs,

I'm currently trying to see if it would be possible to utilize Canvas' lti variable substitution in a probably unique kind of way.  We currently have our tool using variable substitution with custom fields just fine when the variable is the only value in the field, however I would like to substitute the variable as part of a value in the field.

For instance, we are currently passing in the context label as such

series=$com.instructure.contextLabel‍

This works fine, however when I try to include the variable with other information as well, it doesn't work:

tool=admin-ng/index.html?filter=series:$com.instructure.contextLabel‍

The tool launches fine, however looking at what is being sent in the url, it is not replacing the variable, or even trying since there is a %24 code before the com.instructure.contextLabel part, seeming to me that it is trying to pass along the '$', whereas the documentation for lti variable substitution says that it would pass on just the name of the replacement variable if it failed the substitution (ie. in this case it should be sending 'com.instructure.contextLabel' instead of '$com.instructure.contextLabel')

I suppose my main question is whether there exists a way to use variable substitution as I have described in the 'tool' code line?  Is variable substitution only processed if it's the only value in the field?

Thanks,

Jerry

Labels (2)
5 Replies
pklove
Learner II

It looks like you cannot do this.  If you need to be able to specify the static bit per placement, rather than statically or per consumer key at the tool end, then you could use two custom variables (one for the url bit and one for the Canvas variable) and put them together in the tool.

BTW, I think the bit in brackets in the docs is slightly mis-leading, the main bit is "... it will just send the variable as if it were are regular custom variable" --- which means everything to the right of the equals, so the $ does get sent.  E.g., if you use $Canvas.masqueradingUser.id and you are not masquerading, it will send $Canvas.masqueradingUser.id.  Just as if you have $SomethingIMadeUp it will send $SomethingIMadeUp

pklove
Learner II

Actually, you can do this, try un-documented curly brackets:

  tool=admin-ng/index.html?filter=series:${com.instructure.contextLabel}
j_causby
Community Member

This works as you mentioned.  Interesting that the documentation prefers the un-bracketed version of using variables.  I'm going to write a separate post about my findings with using url manipulation with external tools.  Thanks!

phanley
Adventurer

Just chiming in for people finding this, more uses for string concatenation with a custom LTI value.

For example in order to make sure that the correct version of a user's email (for us this is what in shibboleth is eppn, or eduPersonPrincipalName) is passed no matter what, we add the custom value like this:

eppn=${User.username}@institution.edu

and then set the tool provider to use custom_eppn as the email address.

Note: This will pass all Test students and any other user account that doesn't have an sis_id as having an email address when they normally don't, i.e. test students would have an email address like c43bc4c8f7642ddaa4d92b9967d2af8c776c4221@institution.edu, and a non sis_account will be passed as canas_login@institution.edu

This can be avoided by instead using a formulation like

sis_eppn=${Canvas.user.sisSourceId}@institution.edu

However, this might have a stranger effect on LTI launches as all users with out an sisSourceId will be passed with custom_sis_eppn = ${Canvas.user.sisSourceId}@institution.edu, which might cause errors on the other side as ${Canvas.user.sisSourceId}@institution.edu is not a valid email adddress (and if the tool provider accepts it, all non-sis accounts might share an account on the Tool Provider's side, depending on how they implemented their LTI (for the many vendors who use email as their primary account id, this would definitely happen). 

This seems to be a side effect of the the concatenation -- using a simple variable sub instead, i.e.

sis_user_id=$Canvas.user.sisSourceId

is passed as custom_sis_user_id="" for users without a sisSourceId.

MORE FUN

You can do multiple values in a single line, e.g.

tracking_code=${Canvas.account.sisSourceId}/${Canvas.account.name}

hugo_landgren
Surveyor

This was great information. 

I was wondering if you can do the reverse as well? We have the following problem:

Due to "reasons" our login-ids are in the form CID@chalmers.se in Canvas but in most other services it is CID@net.chalmers.se, So I want to extract the CID (Chalmers ID) and add "@net.chalmers.se".

Does anyone know if this is possiblem?

Best regards

/Hugo