Getting variable from url to string field

perlemmingwittu
Kilo Expert

Hi

OK, I'm pretty new at this, and I am building a survey where I can write a value in a url variable with the survey link and have the survey form pick it up in a string field (preferable read-only).

For instance, a case number:

https://<link to survey>&casenumber=FF012345

I manage to view the field Default Answer in the form by removing the conditions regarding when to apply under "Show and hide default value field", but that just gives me an uneditable empty drop-down field, so I suspect I'm on the wrong track

So "all i need" is to be able to put some magic into that field and have it pick up the casenumber variable. Or another idea.

Best regards

Per

1 ACCEPTED SOLUTION

you can use the sysparm_query property to set the values



https://<instance name>.service-now.com/nav_to.do?uri=incident.do?sys_id=-1%26sysparm_query=priority=1^incident_state=3



you can set this values dynamically from email notification while sending survey like below.



https://<instance name>.service-now.com/nav_to.do?uri=incident.do?sys_id=-1%26sysparm_query=assigned_project_title=${short_description}


View solution in original post

9 REPLIES 9

Deepak Kanavika
Tera Expert

Hi Per,



Have a look at the below code, it should run during on Load of the page and should fetch you the 'casenumber' from URL



<code>


function onLoad() {


  var caseNumber = getParmVal('casenumber');


alert('caseNumber : '+caseNumber);


}


function getParmVal(name){


  try{


  var url = document.URL.parseQuery();


  if(url[name]){


  return decodeURI(url[name]);


  } else {


  return;


  }


  }


  catch(e){


  jslog('Exception ' + e);


  }


}


</code>



Do post if you have further questions.



Regards


Deepak Kanavikar



( Hit like, Helpful or Correct depending on the impact of the response )


Hi Deepak



Thanks for that. That fetches the variable from the url, but I still need to transfer the value to the string field.


I need the value to be saved with the survey response.



Best regards


Per


Did you get anywhere with this? I am trying to do something very similar.


you can use the sysparm_query property to set the values



https://<instance name>.service-now.com/nav_to.do?uri=incident.do?sys_id=-1%26sysparm_query=priority=1^incident_state=3



you can set this values dynamically from email notification while sending survey like below.



https://<instance name>.service-now.com/nav_to.do?uri=incident.do?sys_id=-1%26sysparm_query=assigned_project_title=${short_description}