Need to keep dynamic href link on catalog form in portal
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
01-03-2024 11:00 PM
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.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
01-07-2024 09:29 PM
@Ankur Bawiskar Yes they would use in native UI, i mean after clicking dynamic href link it would redirect to native UI
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
01-07-2024 09:31 PM
to open the URL in <script> tag of UI macro you can use window.open
what's the challenge?
Ankur
✨ Certified Technical Architect || ✨ 9x ServiceNow MVP || ✨ ServiceNow Community Leader
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
01-07-2024 09:39 PM
@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.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
01-07-2024 10:09 PM
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.
Ankur
✨ Certified Technical Architect || ✨ 9x ServiceNow MVP || ✨ ServiceNow Community Leader
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
01-07-2024 10:49 PM
@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>