Join the #BuildWithBuildAgent Challenge! Get recognized, earn exclusive swag, and inspire the ServiceNow Community with what you can build using Build Agent.  Join the Challenge.

Relate Survey to Record

guiguille
Giga Expert

Hi all!

I'm facing an issue with a requirement I received: I need to create a way to manually send surveys from our projects (pm_project table). This is why I created a UI action with the following code:

sendSurvey();

function sendSurvey(){

var strInstance = gs.getProperty('glide.servlet.uri').toString();

var strLink = 'assessment_take2.do?sysparm_assessable_type=<SurveySysID>';

var strSurvey = strInstance + strLink;

gs.eventQueue('pm_project.send_survey', current, current.user, strSurvey);

}

This code triggers the event that sends the created link in a system notification.

The thing is that the link works OK, but I'm not able to set as the trigger ID the proper project. To achieve this, I first tried to relate it with the link I sent:

var strLink = 'assessment_take2.do?sysparm_assessable_type=<SurveySysID>%26sysparm_assessable_sysid=';

var strSurvey = strInstance + strLink + current.sys_id;

This didn't worked, so I tried to create the assessment before sending the link. To achieve this, I used the following code:

new global.AssessmentUtils().createAssessments('<SurveySysID>', '', '<UserToCompleteTheSurvey>')

The problem over there is that like that it works, but I need to send the second parameter as blank. I tried to send over there the sys_id of the project I want to relate the survey to, but that doesn't work.

Any thoughts? Any other way to relate an assessment to a particular record?

Thanks!

1 ACCEPTED SOLUTION

ludijormajordeb
Tera Contributor

Hi guiguille



To create a survey, I would recommend you to use the Trigger Conditions, to send survey based on some condition. That would OOtB attach the survey instance to the record, as specified in Configure a trigger condition for a survey



But assuming that you've managed to link the survey instance with a project, I think that you would probably be replicating something like this OOtB UI Action (in the image below, current represents an survey instance already. If you have a reference to survey instance from your project, that would be your "current"):


find_real_file.png.



Please let me know if that helps


View solution in original post

3 REPLIES 3

ludijormajordeb
Tera Contributor

Hi guiguille



To create a survey, I would recommend you to use the Trigger Conditions, to send survey based on some condition. That would OOtB attach the survey instance to the record, as specified in Configure a trigger condition for a survey



But assuming that you've managed to link the survey instance with a project, I think that you would probably be replicating something like this OOtB UI Action (in the image below, current represents an survey instance already. If you have a reference to survey instance from your project, that would be your "current"):


find_real_file.png.



Please let me know if that helps


Hey ludijormajordebarros,



Thanks for the input. I'm marking your answer as the correct one, because what I was doing had a flaw: I was just creating the link to the survey. When the user entered the link, it created the record in the assessment instance table. I modified my process, I created a trigger condition, but I removed the notifications. I moved everything to the assessment instance table, I created a BR to send my own notification, and setting the assigned to of the notification to be the Guest user (I need it to be public). That way, I created a survey related to the project and it can also be accessible to a user without a SN account.



Thanks!


Great guiguille!



I'm glad I could help.