Submitted by viking on 2022/12/01 15:58

I want to change the item (item text) by adding a link if a URL is added to the URL field.

For example:
myItem => myItem (Link) where "Link" is a hyperlink.

This test rule, in the URL field, works:
AME: [item]="test <a href="[url]">(Link)</a>"

It changes the item:
myItem=> test (Link)

However, I want the item to remain, so I tried these:
AME: [item]="[item] <a href="[url]">(Link)</a>"
AME: [item]=[item] "<a href="[url]">(Link)</a>"

None of these works; the item is not changed.

What should the rule be?

Comments

AME will keep changing the item, you should use only the A rule

as to the rule, try A: [item] = [item] & " <a href=[url]>(Link)</a>"

(basic VBScript string concatenation)

But a much better solution is to use so VBScript code to test for the presence of the hyperlink before making changes

 

I almost got it to work:

Function SetLink(Item, URL)
    if Instr(Item,"Link") then
        SetLink=Item                                                       'if item already has a Link, do nothing
    elseif URL<>"" then
        SetLink=Item & " " & "<a href=[url]>(Link)</a>"   'if there is a URL, create the Link
    elseif isnull(URL) and Instr(Item,"Link") then          
        SetLink = replace(Item,"(Link)","")                       'if there is no URL but a Link, then remove the Link (this doesn't work..)
    end If
end Function

The last part, to remove the link, doesn't work. What is wrong?
Also, is there some way to get a message box or something so that I can see the value of SetLink?
 

I got it working;

Function SetLink(Item, URL)
    if Instr(Item,"Link") and URL<>"" then
        SetLink=Item                                                      'if item already has link and a URL, do nothing
    elseif URL<>"" then
        SetLink=Item & " " & "<a href=[url]>(Link)</a>"  'if there is a URL, then create the link
    elseif URL="" and Instr(Item,"Link") then                'if there is no URL but a Link, then remove the Link
        SetLink = replace(Item,"(Link)","")
    end If
end Function

 

p.s. Don't use IsNull(URL) to check if the URL field is blank. Use URL="" (empty string) instead.

 

How do I ?