Need to keep dynamic href link on catalog form in portal

saibharath
Tera Contributor

I have a requirement to have a dynamic href link on catalog form, on clicking this link it will redirect to my custom table in form view. So I have on change client script where i have been passing this dynamic URL link in a  function and calling this function in a macro, but I am unable to write the script in macro which will redirect it.

 

attaching script which i tried. can someone suggest correct syntax.

11 REPLIES 11

@Ankur Bawiskar Yes they would use in native UI, i mean after clicking dynamic href link it would redirect to native UI

@saibharath 

to open the URL in <script> tag of UI macro you can use window.open

what's the challenge?

Regards,
Ankur
Certified Technical Architect  ||  9x ServiceNow MVP  ||  ServiceNow Community Leader

@Ankur Bawiskar 
as i said i have on change client script where i have been passing this dynamic URL link in a  function and using the function in a macro, I just need the syntax how can I pass URL from onchange client script to macro and use it as hyperlink.

@saibharath 

simply call the function and pass the value

explained here

How to call UI macro with a parameter from Catalog client script 

function onChange(control, oldValue, newValue, isLoading) {
   if (isLoading || newValue == '') {
      return;
   }
	setDesc(newValue);
}

And to test it, a UI macro:

<?xml version="1.0" encoding="utf-8" ?>
<j:jelly trim="false" xmlns:j="jelly:core" xmlns:g="glide" xmlns:j2="null" xmlns:g2="null">
	<div id="short_description"/>
	<script>
		function setDesc(text){
		document.getElementById('short_description').innerHTML = text;
		}
	</script>
</j:jelly>

If my response helped please mark it correct and close the thread so that it benefits future readers.

 

 

Regards,
Ankur
Certified Technical Architect  ||  9x ServiceNow MVP  ||  ServiceNow Community Leader

@Ankur Bawiskar 

so if we need to write for hyperlink then, is it so?


function onChange(control, oldValue, newValue, isLoading) {
   if (isLoading || newValue == '') {
      return;
   }
	setDesc(newValue);
}

 

And to test it, a UI macro:

<?xml version="1.0" encoding="utf-8" ?>
<j:jelly trim="false" xmlns:j="jelly:core" xmlns:g="glide" xmlns:j2="null" xmlns:g2="null">
	<script>
		function setDesc(text){
		document.getElementById('syss_id').innerHTML.href = text;
		}
	</script>
<a href="" target="_blank" id="syss_id">link to find assets</a>
</j:jelly>