how to get the url only in javascript shopify - javascript

I have a metafield of type document, and in the ajax query I get the value of this field as
"gid://shopify/GenericFile/31146481287411"
I need the url. I can easily get that url in liquid using file_url:
{{ metafields.custom.document | file_url }}
But I need to get the url specifically in javascript!
Please tell me how I can do this, and is there a workaround?
Thank you.

Store the file url in a string metafield, and get that instead of the GID to a resource. Alternatively, since your JS has to run AFTER Liquid rendering, render the URL into a JS variable and use it as you wish. You have plenty of options.

Related

PowerBi: Query HTML table

What I need
I need to retrieve data from this source . Let's assume I must use only PowerBi for this.
What I did so far
If I use the basic web source option, then the query is just basically an htlm parsing with which I can easily get the data found in the html scope of the page, example:
Source:
The steps I'm following through Web source option:
Query:
(to simplify the example, assume we don't need the dates)
You can download that example .pbix file here.
The problem
The problem is that I need more data, which can't be accessed through the html preview. For example, let's imagine I need to retrieve the data from January 2010 to April 2020. Those king of queries can only be done via this button located in the webpage (which exports the requested data to an Excel workbook):
The idea is to get this process automated, so going to the source and export the excel file all the time is not an option.
Inspecting the element I realized that what it does is execute a javascript function:
The question
As a PowerBi/PowerQuery noob I wonder: Is there any way I can get that data directly with PowerBi (maybe calling the js function somehow)? If there is so, then how?
Thank you in advance.
The solution to my case was to use URL parameters to retrieve de data without parsing the html table.
❌Original URL I was using:
https://gee.bccr.fi.cr/indicadoreseconomicos/Cuadros/frmVerCatCuadro.aspx?idioma=1&CodCuadro=%20400
✔️New URL for the query, adding some parameters:
https://gee.bccr.fi.cr/indicadoreseconomicos/Cuadros/frmVerCatCuadro.aspx?idioma=1&CodCuadro=%20400&Idioma=1&FecInicial=2010/01/01&FecFinal=2040/01/01&Filtro=0&Exportar=True
This procedure only works in this case, because obviously the parameters will not be the same on other web pages.
However, I post this answer to keep the main idea for those who are in a similar situation: first try with the appropriate url parameters to get the data in a different format. Of course you first must know which are the available parameters, which is a limitation.

How can I parse Outsystems OSVSTATE token to subsequent requests in Jmeter?

I have created a jmeter script for Outsystems applications ( by recording and as well as creating raw request) however when I try to pass _OSVSTATE value from login page to subsequent requests I am getting an base64 encoding errors. I tried sending the request with encoding and without encoding but the result is same. Could anyone please help me/ advise me of how to overcome this issue. Any help is highly appreciated.
Looking into View state in OutSystems Applications article I don't think you need to encode/decode the __OSVSTATE parameter, you just need to extract it from the previous response, save into a JMeter Variable and add the variable as the parameter for the next request.
You can extract the value using i.e. CSS Selector Extractor configured like:
Name of created variable: anything meaningful, i.e. OSVSTATE
CSS Selector Expression: input[__id=__OSVSTATE]
Attribute: value
That's it, now you have the parameter value in the ${OSVSTATE} JMeter Variable, feel free to use it where required.

What's the best way to amend a url via javascript?

My wordpress site has a search form that is crap.
It produces this search string: www.mysite.com/properties/?wpp_search[sort_order]=DESC&wpp_search[sort_by]=price&wpp_search[pagination]=on&wpp_search[per_page]=10&wpp_search[strict_search]=false&wpp_search[property_type]=residential_sales%2Cresidential_lettings%2Ccommercial%2Cfine_living&wpp_search[area]=&wpp_search[price][min]=&wpp_search[price][max]=&wpp_search[branch]=-1&wpp_search[bedrooms]=-1&wpp_search[department]=-1#propertycontent
What's the best way to grab this string, and change certain aspects eg:
[sort_order]=ASC
[sort_by]=price
Then reload the page displaying the new string and thus changing the form output?
Try this.
url.replace('[sort_order]=DESC','[sort_order]=ASC').replace('[sort_by]=price','[sort_by]=newPrice');
You can get the url's query portion using location.search. Look for the parameter, modify, reconstruct your url and assign that value to location to load the page with that url.

Read Rewritten URL - javascript

I need to read the original URL from the rewritten path.
this is how i do url rewrite in my webapplication. I don't have codebehind in my application. So i read everything through javascript and call a webservice. While calling the webservice, i need to read query parameter ID and pass it.
Is my url rewrite method is right? if so, how can i read the original URL i.e. pages/products.aspx?ID=123. Because in my browser address bar it shows only product.aspx, i get the same through javascript.
Don't know whether right or wrong way, anyhow I managed to get the query string using JavaScript.
The query string was not visible in the browser window, but in the form tag it is available. So I get that using document.getElementsByTagName('form')[0].action, and completed my task.

Using javascript to create a value in url and submit that value via form?

I have a site that request that they could send out different urls to clients to track what links are being used. I told them to use google analytics but they are requesting to stay away from it.
What they are asking is they want to send a url to there customers such as,
http://www.yoursite.com/?link=Nameoflink
They want to get that cookie and set it.
Then when the contact form is used they want to be able to submit that link name with the form submission to show what links are being used to go directly to there site.
I was told this is possible but i have no knowledge of that custom of javascript or cookie expertise... =/
You can get the value of the params passed in through the url with location.search. To get the value of the param, use the location.search and then find the specific url value, then set that in another hidden text field or something...
if (location.search){
var search = location.search.substr(1).split("&"),
url = search.split("=")[1];
document.getElementById('hiddenInput').value = url;
}
Note- the code above assumes that your search string only contains the URL value & that the URL is first. If not, it is likely this will fail. You can update the code to account for that by checking to make sure that search.split("=")[0]==="url" or expanding it to parse out all of the search params into an object that you can reference by key.
Yeah, google analytics would make this a lot easier, especially if you had a specific page that would serve as a drop-point, telling you how many people click this special link.
Without google analytics, you could get the GET variable values via a PHP or ASP page script and have them set that way, or you can use soley JavaScript to take care of cookie setting and retrieval.
For JavaScript, these links should point you in the right direction:
JavaScript cookies:
(I can only post one link, but check out W3C School's article on JavaScript cookie handling)
Extract GET values via JavaScript:
http://www.go4expert.com/forums/showthread.php?t=2163

Categories

Resources