Quick C/AL Code Question

Hey guys

We want to put a button on our Item page that auto-generates a URL for us. Here’s what I envision:

Custom table (say ID 50009), named Web Address, which has 3 columns, and only one row.
The columns would be something like “Base URL”, “Image Extension”, and “Drawing Extension”.

So let’s say www.oursite.com/images/ is in Base URL, Image extension is “.jpg” and drawing extension is “.dwg”

Basically what I want to do is have it generate www.oursite.com/images/PARTNO.jpg when I click “generate image URL”, and www.oursite.com/images/PARTNO.dwg when I click “generate drawing URL”

PARTNO would just be the item number, or “No.” from the item record.

It’s a pretty simple job of just concatenating values, but I know nothing about C/AL code so I’m not sure how I’d accomplish this. The reason we’d use a custom table is so that we only have to use our developer’s license to add the initial C/AL code, then any end user can update the URL schemas if we change our domains in the future.

I know how to make action buttons on pages, so I really just need the code and where to put said code (would I put it on the page itself, or on the item record, or what?)

We already have “Item Drawing” and “Item Image” fields, which are set as URL fields so they’re clickable - I will set those to read-only so they serve just as a way to check that our pictures are named properly on the web server.

On that note, does anyone know if it’s possible to make clickable links to a FOLDER in Windows Explorer? I noticed that www. and http:// links work fine when you click the little “globe” button which navigates to the page, but if I put in a C://File, even a file://C:, UNC paths etc, none of those work. NAV just throws an error.

Hi Danny,

For your concatenation function, take a look at the STRSUBSTNO function. For making a button to open a folder, look at HYPERLINK.

Hmm, right now on the Page it looks like this:

7380.Capture.PNG

When I go to edit the Page, it’s just the field with Extended Datatype set to URL. That seems to make the little globe icons show up.

Is there a better way to do that?

As for the STRSUBSTNO, it seems simple enough, but where do I put the code? On the page? e.g. would I make a new action button, and then put it there?

So that’s going to depend on how you want to call the function. I would imagine that you’d want to run the process against all Item records initially, and thereafter do it manually on individual entries.

I would create a codeunit for housing general functions, and in that codeunit I’d add a function to populate these fields. In that function, you could either use the brute-force method of hard-coding the literal segments of the url. Or, you could put those literals in a setup table, which would allow you to change the values without having to change the code. Once you’ve made that function, you can call it from an Action on the Item Card page for individual items, or from a report to process all of them.

Actually, I’m thinking a much simpler solution.

Turns out, someone who worked here before I did had already made this somewhat functional, only instead of storing it in a field it actually opened a browser.

companyInfo_lr.GET;
HYPERLINK(companyInfo_lr.“Item Specification URL” +“Item Category Code”+’/’+ “No.” +’.pdf’);

companyInfo_lr is a C/AL global that’s tied to the Company Info table. I could just as easily make another variable tied to my new table, or just add some columns to Company Info, I guess it doesn’t matter either way.

Since we’d have both JPG images and PDF files, I would think it’s more something like “tableVariable.“Base URL” + ‘/’ + “Item Category Code” + ‘/’ + “No.” + tableVariable.“Image Extension””

Is it just as easy to store values this way than it is to use HYPERLINK? Because if so I might not even need STRSUBSTNO, I could just make a temp variable, set it equal to the above, and then save it to that field.

Creating a codeunit might save some hassle but it sounds like a lot more setup work. We’d really only have links for the products we have parametric data for, which is only a small subset of our total parts (like 2% at the moment) so it’s just as easy to push the button for each one. That C/AL code was set to OnAction() for the action he created (it wasn’t promoted, so I didn’t see it - it’s in the menus somewhere)

Sorry to write it so late but it may help others who are trying …[:)] .

… for url(Hyperlink) to declare in page . i.e i mean you should write the Url(say ‘www.dynamicsuser.net’) as text and in properties

Go for ExtendedDatatype as URL. Then run the page u can see that link …

OR Else u can use RecordLinks Anyway in which u can enter links,files and u can give permissions for client Read only or can modify etc…