Setting a default value to the field(smiley) in the survey by passing parameters through survey URL?

shaikjaheer
Giga Contributor

We have a requirement to send a resolution notification with smileys to take the survey. Once the user clicks on any smiley image, then it should redirect to survey form in Servicenow with the selected smiley image as default.

We are using Service Portal "Take_Survey" widget.

Please suggest how we can achieve this by passing parameters in the URL and set values in take_survey widget.

Thanks in Advance..!!

7 REPLIES 7

Bhagyashree8
Kilo Guru

Hi,

 

I can help you with this, Please share how much you were able to do or where you are stuck.

shaikjaheer
Giga Contributor

Hi Bhagyasree,

Thanks for your help.

We have created a notification with smiley Images. When the user clicks on smiley image then we are appending the image value to the URL like &customer=excellent.

customer is a variable to pass the value.

The link is redirecting to survey page (take_survey) in Service portal.

On Survey form, we have a template with smiley Images and few questions.

Our requirement is the image(value) which have been selected in the notification will be displayed as selected smiley Image (default) on the survey form.So user again no need to select the image on the survey i.e. the same value should be passed from notification to survey form.

Please suggest how i need to extract that value from URL and set that smiley image value on the survey form as selected.

 

 

 

Mike Patel
Tera Sage

On you notification, add link to each smiley with score. like if I click on 1st smiley face than score=1 and for last face score=5.

Than on your take survery widget grab that info from url.

on server script add something like 

var score = $sp.getParameter("score") || '';

once you have that than you can set value on your question.

shaikjaheer
Giga Contributor

Hi Mike,

 

Thanks for your response.

 

I have tried in multiple ways to fetch the Question label, based on that question i am trying to set the Parameter value, but no luck.

Sorry I am not familiar with Angular JS.

 

In the below script, we are getting the selected value in Client Controller:

 

var fieldValue = (field.type != 'template') ? field.value : c.data.questions.idMap[field.sys_id].value;

return fieldValue != null && fieldValue != undefined && fieldValue != '';

 

I have noticed that it is calling "SPSurveyAPI" script include, where we can see all the questions

++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++

function AssessmentQuestion(gr) {
            this.sys_id = gr.getValue('sys_id');
            this.metric = gr.getValue('metric');
            this.category = {display: gr.getDisplayValue('category'), sys_id: gr.getValue('category'), order: parseInt(gr.category.order+'')};
            this.mandatory = Boolean(gr.getElement('metric.mandatory'));
            this.value = gr.getValue('value');
            this.details = gr.metric.details + '';
            this.randomize = ((gr.metric.randomize_answers + '') == 'true');

            this.label = gr.getDisplayValue('metric.question');
                gs.info("test2 Label Value:"+this.label);


            this.attributes = "";
            this.type = gr.metric.datatype+'';
            this.name = 'ASMTQUESTION:' + this.sys_id;
      
            var allowNA = gr.getDisplayValue('metric.allow_not_applicable') == 'true';

            this.depends_on = gr.metric.depends_on + '';
            if (this.depends_on) {
                this.displayed_when = gr.metric.displayed_when + '';
                this.displayed_when_yesno = gr.metric.displayed_when_yesno + '';
                this.displayed_when_template = gr.metric.displayed_when_template + '';
                this.displayed_when_checkbox = gr.metric.displayed_when_checkbox + '';
            }

            switch (this.type) {
                case 'imagescale':
                    this.choice = 0;
                    this.choices = fetchChoices(allowNA, this.metric, this.type);
                    //gs.info("Jaheer test2 Choices Value:"+this.choices);
                    this.selectedImageOnly = hasSelectedImageOnly(this.choices);
                    this.unSelectedImageAllPresent = hasAllUnSelectedImages(this.choices);
                    //gs.info("Jaheer test1 selected Image:"+this.selectedImageOnly);
                    //gs.info("Jaheer test1 unselected Image:"+this.unSelectedImageAllPresent);
                    break;
                case 'multiplecheckbox':
                    var metric = gr.metric + '';
                    var value = gr.value + '';
                    var found = false;
                    data.questions.idList.forEach(function(questionId) {
                        var question = data.questions.idMap[questionId];
                        if (question.metric == metric) {
                            question.choices.forEach(function(choice) {
                                if (choice.value == value)
                                    choice.selected = true;
                                gs.info("Jaheer test2 selected Value:"+value);
                            });
                            found = true;
                        }
                    });

++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++

Can you please share the script to set Image value based on URL parameter.

 

Appreciate your help..!!