I have received response from an api call, it is svg image , i need to append this to catalog item
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
01-30-2023 02:54 AM
Response received is
<svg xmlns="http://www.w3.org/2000/svg" viewBox="0 0 400 400">
<title>code assembly</title>
<g id="0b6f0a07-2ae9-4077-ac96-42fdc93a6dd4" data-name="Layer 2">
<path d="M188.11,200l87.5-87.21L202.32,
40.07a35.39,35.39,0,0,0-49.73,0L16.41,175.24a34.93,34.93,0,0,0,0,49.52L152.59,359.93a35.38,35.38,0,0,0,49.73,
0l73-72.43ZM163.86,51.42a19.37,19.37,0,0,1,27.19,0l61.74,61.29-76,76-75.34-75.33ZM22.12,200a18.77,18.77,0,0,
1,5.56-13.41L90.1,124.64,165.48,200,90.12,275.38l-62.44-62A18.77,18.77,0,0,1,22.12,200ZM191.05,348.58a19.37,
19.37,0,0,1-27.19,0l-62.38-61.93,75.32-75.32,76,76Z" fill="#0065ab"/>
<path d="M309.16,298.94l74.43-73.87a34.93,
34.93,0,0,0,0-49.52l-74.38-73.83-98.6,98.63Zm63.16-85.23-63.1,62.63-76-76,76-76,63.08,62.61a18.94,18.94,0,0,1,0,
26.81Z" fill="#60b515"/>
</g>
</svg>
I need to append this image to catalog item icon field.
How to parse this response and how to append it to catalog item icon field
pls help
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
01-30-2023 06:55 AM
Hello Sachin,
Store the response in a variable in a client script.
Encode the SVG data as Base64 string using a function such as btoa() in JavaScript.
and then Assign the encoded string to the Catalog Item Icon field.
something like this
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
01-30-2023 10:11 AM
Thanks @Prasad Dhumal , will try this and will let you know here. Thanks
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
01-30-2023 10:56 AM
Hi @Prasad Dhumal , I tried it in background script but getting below error
"
com.glide.script.RhinoEcmaError: "btoa" is not defined. script : Line(2) column(0)
"
Can you please help me
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
01-30-2023 01:57 PM
Instead of btoa, try something like this to decode :
var strEncodedString = GlideStringUtil.base64Encode(svgResponse);