How to parse assessment instance url to get the "accessable_type"

sharepointau
Giga Guru

I'm creating an email script to build an assessment link to send users. However, the "no code" way sends users to the platform. This way is hideous and feels odd. We want to send users to the portal's "take_survey" page to complete all assessments. 

I understand the below gets me the "no code required" link that does in fact link to the form. That looks like this:
https://instance.service-now.com/nav_to.do?uri=assessment_take2.do%3Fsysparm_assessable_type=e1768da91b54c8904750bbfccd4bcb54%26sysparm_assessable_sysid=b9504f5fdb104410551680f33996194f

AssessmentUtils().getAssessmentInstanceURL(current.sys_id)

The "sysparm_assessable_type" is what I need to build the URL to send our users to the correct place:
https://instance.service-now.com/it?id=take_survey&type_id=e1768da91b54c8904750bbfccd4bcb54

However, no matter what I do to try and get this "sysparm_assessable_type" it renders as "undefined."

Below is the script I last tried to pull it out and I thought for sure it would work, but it's not.  

var assessmentURL = new AssessmentUtils().getAssessmentInstanceURL(current.sys_id);	

var assessmentSysID = String(assessmentURL).subString(94, 126);
7 REPLIES 7

Chuck Tomasi
Tera Patron

The URL you supplied doesn't have a sysparm_assessable_type in it. 

If it did, you could use GlideURI to get at the various arguments in the URI.

GlideURI - Scoped | ServiceNow Docs

So you are saying the one I supplied that is out of the box (https://instance.service-now.com/nav_to.do?uri=assessment_take2.do%3Fsysparm_assessable_type=e1768da91b54c8904750bbfccd4bcb54%26sysparm_assessable_sysid=b9504f5fdb104410551680f33996194f) should allow me to use GlideURI? 

Could you explain how that would help me get my users to the take_survey page like my post is asking?

You can use GlideURI to get at the various components of the URI provided in the classic UI. The ID provided to assessable_type appears to map to the type_id in the portal widget, but I don't know what you would do with

sysparm_assessable_sysid=b9504f5fdb104410551680f33996194f

or if it's needed. Try manually building the URL with you hands before testing this with a script. If it works the way you want, then you can script it. GlideURI is going to be your friend.

Thanks for your quick responses. 

As stated in my post I have manually built it, and need to dynamically pull out the "sysparm_assessable_type" to build the desired URL in the email script. 

I like the idea of grabbing the "sysparm_assessable_type" from the prebuilt URL produced by AssessmentUtils().getAssessmentInstanceURL(current.sys_id); however, I'm not sure how to get the variable used to capture that in the GlideURI. 

Would I simply do something like this?

var assessmentURL = new AssessmentUtils().getAssessmentInstanceURL(current.sys_id);

var gURI = new GlideURI(assessmentURL);
var assessmentSysID = gURI.get('sysparm_accessable_type');