cancel
Showing results for 
Search instead for 
Did you mean: 

Keeping the WebRFC URL dynamic in Personas

tamas_hoznek
Product and Topic Expert
Product and Topic Expert
0 Kudos

I'm not sure if this is common knowledge so I thought I'd mention it

In order to avoid a hard coded server name when performing a WebRFC, there is a very simple way to build the URL in a dynamic fashion. Just precede the WebRFC step with a Javascript step which builds a variable from the current protocol and host name and use that in the WebRFC step. So something like this:

Calculate in JavaScript     args.server = location.protocol + '//' + location.host;

Call WebRFC                        {server}/sap/bc/webrfc?_FUNCTION=functionnname...etc...

This avoids having to alter the flavor when it gets transported to another environment like from Dev to QA and so on.

Accepted Solutions (1)

Accepted Solutions (1)

Former Member
0 Kudos

Thanks Tamas. I've been meaning to add this info to my WebRFC blog for a while. Now I just need to add a link pointing here

Is it worth also adding the port number to the calculation?

Steve.

tamas_hoznek
Product and Topic Expert
Product and Topic Expert
0 Kudos

It shouldn't be necessary since location.host will return both the server name and the port: Location host Property

Former Member
0 Kudos

Oh, yes. I was thinking of the hostname property, which doesn't include the port number. Sorry!

Steve.

Answers (3)

Answers (3)

0 Kudos

Hi Tamas

Thank for your post on Dynamic URL.

Due to I have to add another parameter for sap client in URL as below

Call WebRFC       {server}/sap/bc/webrfc?_FUNCTION=XXXXX&_name={name}&sap_client=110

I don't want to hard code 110, how do I get the sap-client dynamic, Please advise.

Regards

Nat

Former Member
0 Kudos

Hi,

You can set the client the same way as for {name}
so:

In JS code:

args.my_client=Val_Copied_from_UI_field

&sap_client={my_client}

where my client can be a variable set in JS or copied from an UI field.

Hope this helps.

Br,


Dong

0 Kudos

Hi Dong

I have done as you say by put JS code:

args.my_client = Val_copied_from_UI_field

I get the scripting error on the above JS code.

{server}/sap/bc/webrfc?_FUNCTION=XXXXX&_name={name}&sap-client={my_client}

Can you give me the exact JS code, due to I am not expert on JS.

Thanks

Nat

tamas_hoznek
Product and Topic Expert
Product and Topic Expert
0 Kudos

Why are you trying to pass the client number in the webRFC step? It is not needed to perform a successful call.

Can you explain your use case where the client number would be necessary?

0 Kudos

Hi Tamas

Due to in our development system, we have 2 client 100 and 110.

Client 100 for Development and configuration work and client 110 for testing,

All data is in client 110.

When we log on to personas, we log into 100 and choose the system 110,

When I did the JS to call WebRFC, if I do not put &sap-client=110, there is no result come back.

So I think it will pass to client 100.

tamas_hoznek
Product and Topic Expert
Product and Topic Expert
0 Kudos

This sounds like a multi-system configuration.

The webRFC call will use your logon client as default. Personas 2.0 scripting has no exposed method to determine that you chose a different client after the logon.

0 Kudos

Thank Tamas for your clarify.

It will not have the issue when we move to QA system coz it only has one client in QA.

Former Member
0 Kudos

Hi,

In your case, I guess you can do like this:

You can set 100 and 110 on Dev system using SPRO so that when you logon Personas, you have to choose which client system is to be used (or put client in url of your app).

Your Personas app can be made for both systems, and the WebRFC module may have to be copied onto the two systems too. Then on UI, you will need to call the module without specifying the client number.

Just for testing purpose, I haven't done dynamic client number by just 'name' as normally you don't specify that in the url as you can specify that in your personas app url.

Br,


Dong

Former Member
0 Kudos

Hi,

Just want to provide simplified info for doing RFC regarding the info split into several posts. Here is the script of calling RFC with dynamic domain (from Tamas) and random number for constantly updating UI value:

It works fine even with special (eg danish chars), see below:

Hope this help someone to get RFC work a bit easily.

Br,

Dong Zhu

mahabaleshwar_patil
Participant
0 Kudos

Hello,

Can we delete the Table entries through the ABAP Logic by calling the Web RFC from the personas  screen ??

if yes can you please demonstrate how to do it ?

Former Member
0 Kudos

You can write a webRFC to do pretty much anything. Details of how you call webRFCs from personas are in this blog: Calling RFCs from a Personas script. You just need to make the function body do whatever you need.

I need to add, what table entries are you planning to delete? You need to be very careful manipulating standard SAP tables in this way. It is almost always wrong...

Steve.