EXCEL How to change the REST URL based on the cell parameters - json

I created a web query as below in Excel.
New Queries --> From Other Sources --> From Web
How do I pass in the cell value as a parameter to the Url?
I have search bunch of articles, including in the stackoverflow. None of them work.
There is 1 article says I can do this in VBA.
ThisWorkbook.Sheets("[SheetName]").QueryTables("[TableName]").Connection =
But it is not there.
Any one know how to do this?
More information:
It is connecting to a REST server, and geting back the JSON result.
I found an article discussing how to create a query link mine, but it has not options to add the parameters. Please see the link. Step 3 have the URL typed in.
https://success.planview.com/Planview_LeanKit/Reporting/Advanced_Reporting/030Configure_A_Connection_To_The_Reporting_API_With_Excel

Give the cell a name, e.g. pMyParameter.
Open the query editor and create a new blank query (New Query --> Other Sources --> Blank Query). Give that query a name similar (or same) to the cell name (let's call it pMyParameterQuery). Open the Advanced Editor and replace everything with the following.
let
Source = Excel.CurrentWorkbook(){[Name="pMyParameter"]}[Content]{0}[Column1]
in
Source
You'll see in the query list that this query does not return a table but text (or a number / date / ... depending on the contents of your named cell).
Now switch to your web query and open its Advanced Editor. Find the line that has the URL, probably something like this:
Source = Web.Page(Web.Contents("http://www.example.com?someParameter=someValue")),
Here you can use the result of the parameter-query in the URL like this:
Source = Web.Page(Web.Contents("http://www.example.com?someParameter=" & pMyParameterQuery)),

Related

SSIS - Loop Through Active Directory

Disclaimer: new to SSIS and Active Directory
I have a need to extract all users within a particular Active Directory (AD) domain and import them into Excel. I have followed this: https://www.itnota.com/query-ldap-in-visual-studio-ssis/ in order to create my SSIS package. My SQL is:
LDAP://DC=JOHN,DC=JANE,DC=DOE;(&(objectCategory=person)(objectClass=user)(name=a*));Name,sAMAccountName
As you know there is a 1,000 row limit when pulling from the AD. In my SQL I currently have (name=a*) to test the process and it works. I need to know how to setup a loop with variables to pull all records and import into Excel (or whatever you experts recommend). Also, how do I know what the other field names are that are available to pull?
Thanks in advance.
How do I see what's in Active Directory
Tool recommendations are off topic for the site but a tool that you can download, no install required, is AD Explorer It's a MS tool that allows you to view your domain. Highly recommend people that need to see what's in AD use something like this as it shows you your basic structure.
What's my domain controller?
Start -> Command Prompt
Type set | find /i "userdnsdomain" and look for USERDNSDOMAIN and put that value in the connect dialog and I save it because I don't want to enter this every time.
Search/Find and then look yourself up. Here I'm going to find my account by using my sAMAccountName
The search results show only one user but there could have been multiples since I did a contains relationship.
Double clicking the value in the bottom results section causes the under pane window to update with the details of the search result.
This is nice because while the right side shows all the properties associated to my account, it's also updated the left pane to navigate to the CN. In my case it's CN=Users but again, it could be something else in your specific environment.
You might discover an interesting categorization for your particular domain. At a very large client, I discovered that my target users were all under a CN
(Canonical Name, I think) so I could use that in my AD query.
There are things you'll see here that you sure would like to bring into a data flow but you won't be able to. Like the memberOf that's a complex type and there's no equivalent in the data flow data types for it. I think Integer8 is also something that didn't work.
Loop the loop
The "trick" here is that we'll need to take advantage of the
The name of the AD provider has changed since I last looked at this. In VS 2017, I see the OLE DB Provider name as "OLE DB Provider for Microsoft Directory Service"
Put in your query and you should get results back. Let that happen so the metadata is set.
An ADO.NET source does not support parameterization as the OLE DB does. However, you can apply an Expression on the Data Flow which surfaces the component and that's what we'll do.
Click out of the Data Flow and back into the Control Flow and right click on the Data Flow and select Properties. In that properties window, find Expressions and click the ellipses ... Up pops the Property Expressions Editor
Find the ADO.NET source under Property and in the Expressions section, click the Ellipses.
Here, we'll use your same source query just to prove we're doing the right things
"LDAP://DC=JOHN,DC=JANE,DC=DOE;(&(objectCategory=person)(objectClass=user)(name=" + "a" + "*));Name,sAMAccountName"
We're doing string building here so the problem we're left to solve is how we can substitute something for the "a" in the above query.
The laziest route would be to
Create an SSIS variable of type String called CurrentLetter and initialize it to a
Update the expression we just created to be "LDAP://DC=JOHN,DC=JANE,DC=DOE;(&(objectCategory=person)(objectClass=user)(name=" + #[USer::CurrentLetter] + "*));Name,sAMAccountName"
Add a Foreach Loop Container (FELC) to your Control Flow.
Configure the FELC with an enumerator of "Foreach Item Enumerator"
Click the Columns...
Click Add (this results in Column 0 with data type String) so click OK
Fill the collection with each letter of the alphabet
In the Variable Mappings tab, assign Variable User::CurrentLetter to Index 0
Click OK
Old blog posts on the matter because I like clicks
https://billfellows.blogspot.com/2011/04/active-directory-ssis-data-source.html
http://billfellows.blogspot.com/2013/11/biml-active-directory-ssis-data-source.html

How to Search Access DB and Make A DB Wide Search & Replace Operation

we have an access database. We had been using http://www.example.com on various data sections. Now we want to search this URL and replace all occurrences.
I am not sure if Find and Replace utility works in this case. Because Look in field is set to Current Document but my search does not bring expected results.
The goal is only changing domain name so any URL that starts with http://www.example.com will be updated and URLs will start with http://www.newexample.com
One thing that comes to my mind is exporting 40 tables as CSV and doing the operation via Notepad++ and import the resulting CSV file back to database.
In the Find and Replace dialog, make sure that Match is set to Any Part of Field.

Retrieve Google Spreadsheet Worksheet JSON

I try to receive the JSON of a Google Spreadsheet Worksheet. It worked till some days ago. For the default worksheet it still works, but not for all other worksheets.
This is the working URL for the default worksheet: https://spreadsheets.google.com/feeds/list/1caRqAA1TyBoZ0eVZvvKheEBh9SGRmQII4qih9urY70k/od6/public/full?alt=json
And this is the URL for the worksheet that stopped working: https://spreadsheets.google.com/feeds/list/1caRqAA1TyBoZ0eVZvvKheEBh9SGRmQII4qih9urY70k/1416241220/public/full?alt=json
The error message is Invalid query parameter value for grid_id.
Only difference is the worksheet parameter (od6 vs 1416241220).
Any ideas on why that error suddenly occurs?
ChrisPeterson's note:
You can use worksheet position number (1 for the first/default worksheet, 2 for the second worksheet).
Original answer
I came across the same issue and I managed to find my way out.
It seems that they recently changed the id for each worksheet.
You can find the new ID at the following
https://spreadsheets.google.com/feeds/worksheets/YOUR_SPREADSHEET_ID/private/full
I got something like o3laxt8 between <id> tags
Ps: od6 anddefault values will always work and redirect to the first worksheet of your document.
Joe Germuska' note:
od6 doesn't work anymore
Seems to work again.
I'd like to share a concrete example because I find there are enough confusing instructions out there including the accepted answer and worksheet IDs and where to put them not being obvious.
Here's a document I published and anyone with the link can view:
https://docs.google.com/spreadsheets/d/1QDWpycJJFA-UAiSPIv-icJ4UZhbEmuN8wxxag83SE1c/edit?usp=sharing
The document has to be published correctly. There are two Publish buttons and the first one doesn't work for this task. Use the second.
The document KEY is important. Obtain the KEY from between the /d/ and the /edit in the url. In my example, the key is 1QDWpycJJFA-UAiSPIv-icJ4UZhbEmuN8wxxag83SE1c.
Second, use the following URL style, replacing KEY with your own:
https://spreadsheets.google.com/feeds/list/KEY/od6/public/values?alt=json
My example url links directly to published json:
https://spreadsheets.google.com/feeds/list/1QDWpycJJFA-UAiSPIv-icJ4UZhbEmuN8wxxag83SE1c/od6/public/values?alt=json
Finally, if the worksheet has multiple sheets (or tabs), replace od6 in the url with a number. My example has two tabs, so there are two urls corresponding to either tab. I simply replace od6 with 1 and 2 depending on the order of the sheets:
Tab 1:
https://spreadsheets.google.com/feeds/list/1QDWpycJJFA-UAiSPIv-icJ4UZhbEmuN8wxxag83SE1c/1/public/values?alt=json
Tab 2:
https://spreadsheets.google.com/feeds/list/1QDWpycJJFA-UAiSPIv-icJ4UZhbEmuN8wxxag83SE1c/2/public/values?alt=json
In the event of a worksheet where the tabs are reordered frequently, it is possible to get the ID of a given sheet and use that instead of ordered numbers. I first learned of this approach from this post or this post:
In brief, you would reform a private URL with your KEY:
https://spreadsheets.google.com/feeds/worksheets/KEY/private/full
This only works on a browser where you are logged into Google Drive on an account with permissions.
Next, you have to sift through XML to find your sheet IDs:
Replace the previous 1 and 2 with the IDs, for example:
Tab 1 (first worksheet id in a new google sheet is always od6 by default, no matter order of tabs):
https://spreadsheets.google.com/feeds/list/1QDWpycJJFA-UAiSPIv-icJ4UZhbEmuN8wxxag83SE1c/od6/public/values?alt=json
Tab 2:
https://spreadsheets.google.com/feeds/list/1QDWpycJJFA-UAiSPIv-icJ4UZhbEmuN8wxxag83SE1c/ope57yg/public/values?alt=json
You can find the new ID at the following
https://spreadsheets.google.com/feeds/worksheets/YOUR_SPREADSHEET_ID/private/full

PowerBuilder pasting in tabbed data window

I recently started a new job with a company and my first task is to update some quite old software for them.
There is a big back story but basically the software was written in PB8 (around 1997) and no one within the company (including me) has had any experience with PowerBuilder before and as the newbie I have been tasked to update and maintain it until a replacement has been approved and can be developed.
We have the license for PowerBuilder 12.5 so I am using PB12.5 Classic to do everything. The original developer cannot be contacted for support and no documentation exists.
One thing I am trying to understand, that will be a huge help in the future, is how to determine where functions are defined and where variables get their values..
The example I am working on at the moment is the following scenario.
There is a data window with tabs, named tab_detail each tab displays different whatever little orange men are in the tree list.
One of these are called dw_detail which allows pasting of data. None of the other tabs allow pasting of data, but I would like them to. dw_detail has an event rbuttondown() with the following code in it:
Window w_parentwin
If ib_add_mode Or ib_chg_mode Then
w_parentwin = Parent.GetParent().GetParent()
m_dwpaste m_pop_paste
m_pop_paste = CREATE m_dwpaste
m_pop_paste.idw_data = This
If ii_agent_code > 0 And Not IsNull(id_period) And Clipboard() <> "" Then
m_pop_paste.m_popup.m_paste.Enabled = TRUE
Else
m_pop_paste.m_popup.m_paste.Enabled = FALSE
End If
m_pop_paste.m_popup.PopMenu(w_parentwin.PointerX(), w_parentwin.PointerY())
DESTROY(m_pop_paste)
End If
When I add that code to the rbuttondown() event of tab number 2 (dw_adjustment) tab 2 now allows paste when I right click within the dw_adjustment data window but the data gets pasted to the fields within the dw_detail tab not the fields on the dw_adjustment tab.
I have tried debugging and stepping through the code but there are thousands of values in the variable window and without the ability to search I cannot find the variables used above and what their values are or why data gets pasted to the dw_detail tab instead of the dw_adjustment tab when I paste into the dw_adjustment tab.
Basically I am looking for any helpful tips on where to look or what the above is doing and why everything pastes to tab 1 instead of the tab I clicked paste in.
If more detail is needed from code from a different location or more information is needed I am happy to provide it.
As suggested by Seki I found the m_popup when double clicked it came up with wf_pastereturn():
Integer li_idx, li_rows, li_dwrows, li_comm, li_seqno
String ls_approval_type
If tab_detail.tabpage_details.dw_detail.RowCount() > 0 Then
li_idx = 1
li_dwrows = tab_detail.tabpage_details.dw_detail.RowCount()
Do Until li_idx > li_dwrows
ls_approval_type = tab_detail.tabpage_details.dw_detail.Object.approval_type [li_idx]
If IsNull(ls_approval_type) or ls_approval_type = "" Then
tab_detail.tabpage_details.dw_detail.DeleteRow(li_idx)
Else
li_idx++
End If
li_dwrows = tab_detail.tabpage_details.dw_detail.RowCount()
Loop
End If
If li_dwrows > 0 Then
li_seqno = Long(tab_detail.tabpage_details.dw_detail.Object.seq_no [li_dwrows])
End If
li_seqno += 10
If Clipboard() <> "" Then
If tab_detail.tabpage_details.dw_detail.ImportClipboard(1, li_rows, 1, 4, 3) <= 0 Then
MessageBox("Invalid Data", "Unable to paste!", StopSign!)
Return -1
End If
li_rows = tab_detail.tabpage_details.dw_detail.RowCount()
li_dwrows++
For li_idx = li_dwrows To li_rows
tab_detail.tabpage_details.dw_detail.Object.approval_type [li_idx] = trim(tab_detail.tabpage_details.dw_detail.Object.approval_type [li_idx])
tab_detail.tabpage_details.dw_detail.Object.approval_no [li_idx] = trim(tab_detail.tabpage_details.dw_detail.Object.approval_no [li_idx])
tab_detail.tabpage_details.dw_detail.Object.agent_code [li_idx] = ii_agent_code
tab_detail.tabpage_details.dw_detail.Object.period [li_idx] = id_period
li_comm = f_new_commission(Long(tab_detail.tabpage_details.dw_detail.Object.value_of_work[li_idx]), id_period)
tab_detail.tabpage_details.dw_detail.Object.levy_payable[li_idx]= &
inv_rate.of_CalculateLevyPayable (Long(tab_detail.tabpage_details.dw_detail.Object.value_of_work[li_idx]), id_period)
tab_detail.tabpage_details.dw_detail.Object.comm_deductable [li_idx] = li_comm
tab_detail.tabpage_details.dw_detail.Object.commission [li_idx] = li_comm
tab_detail.tabpage_details.dw_detail.Object.seq_no [li_idx] = li_seqno
li_seqno += 10
tab_detail.tabpage_details.dw_detail.Object.agent_return_detail_create_date[li_idx] = Today()
tab_detail.tabpage_details.dw_detail.Object.agent_return_detail_create_user[li_idx] = SQLCA.Logid
Next
Clipboard("")
Return 0
Else
Return -1
End If
I modified the function to use the windows SelectedTab property. Data will now paste into the tab but in the wrong input fields. I looked further and the data columns for the ImportClipboard function do not line up.
How is the best way to change the order of the selected database columns?
Here is a screenshot of what I mean by tabs:
So within the main program window, there are the above tabs, within each tab (where the input fields are) there is a data window labelled with the dw_ prefix.
Thanks heaps for your help.
I think first you should do some short tutorials. Please check out these:
PowerBuilder Classic 12/12.5 guide/tutorials
These are short and useful.
On the other side you are able to select specific variables in your own "watch variable" list, so you do not have to search over the several variables. You can right click on the variable name and do a Quickwatch or you can Insert the variable name in the Watch window.
Br. Gábor
The action with a contextual menu is in 2 times :
handle the mouse right click to display a contextual menu
perform an action among the one or several actions provided by the popup menu
You shown the pbscript that is displaying the menu with PopMenu() if there is something in the clipboard (Clipboard() <> "") and maybe you did not noticed that the pasting action is somewhere else.
Look in m_popup: there must be some code inside that may be hard-coded to paste in dw_detail. If so, maybe that you could store in the window instance variables a reference to the currently processed dw for the contextual menu.
Something like :
datawindow idw_current in the instance variables
then in the rbuttondown() event idw_current = this (this being the datawindow the rbuttondown() event belongs to)
and finally in the menu reuse the id_current instead of a hardcoded dw_detail
Concerning your question about where the variables are modified: what you can do is searching the variables by their name (right click on the target or a single pbl or object then 'search'), and put a breakpoint on the lines where they are affected. If you run in debug mode (CtrlDCtrlT instead of CtrlR) you will be able to trace when a variable is modified.
Paste Problem
Pass 1
It's hard to tell for sure, but I'd look at the code of m_dwpaste.m_popup.m_paste.Clicked. The worse case scenario is that dw_detail is hard coded into that script; the slightly better case is that it has a more flexible routine in there, but somehow dw_adjustment doesn't fit into that algorithm.
Pass 2
With the new information, we can see that the code of wf_pastereturn() (I'm not sure how you got to this script, but this looks like the culprit) is not simply pasting, but doing a lot more that involves specific fields. In fact, it's not just pasting, it's importing the data, which means that it's assuming the contents of the clipboard are not only in a specific format, but match the data set of the DataWindow (see the Columns pane in the DW painter, and be careful not to confuse the data set part of the DataWindow with the UI part). The question is, do you want:
"Pasting" like copying text from Notepad into a browser form; just putting text into the current field?
"Pasting" exactly like the other DataWindow, including assumptions that all the same columns mentioned in the script are in both DataWindows?
"Pasting" something like this script, but customized for the data set in the new DataWindow?
These all require somewhat different solutions, combined with the differences I asked about in my comment about tabs vs. DataWindows.
Finding Stuff
I'm going to give an unapologetically biased point of view, because I'm the author of a tool that, among other things, helps you search PowerBuilder code called PBL Peeper.
If you're looking at code in the Browse tab, and you want to see other mentions of the variable, you can select it, right click, and either
search forward or back within the script
search for the object name in the tree on the left (it'll make more sense when you see it)
search either the rest of the object or the rest of the application
Finding where a variable is assigned is more difficult than it sounds, because of the multiple syntaxes that could be involved.
// assigns a value on instantiation
int i = 1
// assigns a value when executed
i = 1
// does not assign a value
IF i = 1 THEN
// assigns a value possibly if the parameter is passed by reference (kind of like a pointer to the variable)
f_foo (i)
Finding the setting of a variable can be helped by understanding variable scope. If the variable is local, you only need to search the script. If the scope is instance or shared, you need to search the object (as above, pretty easy) and its descendants (easy to go to a given descendant with an RMB on the treeview, harder to search on a set of descendants). If the scope is global, you want to search the entire app.
Finding where a selected function is declared is possible, but you need to know a little secret (or RTFM). The Find on the RMB menu uses the parameters from the Find page, so you need to set Portion Type to All, not just Scripts, to find where functions are declared. Alternatively, you can use the Lists / Scripts pages and find the script using the functions on that page (Find, QuickFind, Filter, etc...).
The tool has a plethora of functionalities that let you find, filter and sift through code to get at what you're after. The above is just a quick introduction.
Good luck,
Terry.

Designing Database

I need to design database with frontend as HTML.
This is my first attempt to do this.
What I need is,
- User can input a word from HTML page, click submit
I will query the word to get a URL from database and user sees that webpage(pointed by URL).
Just enter word, submit and get the webpage displayed.
People suggested using JSP/Access. I am new to everything.
Can you please point out what exactly I need to do?
Thanks a ton.
Following is the way you need to approach
Step1:
Create an HTML page which can take an input from the users
Step 2:
After getting the data from the user, create a connection to the database and pass the searched string as an input paramater.
Step 3:
You will get a result set from a database
Step 4:
Iterate through the result set and display in the html page, if you require the url to be given for those url, so when user clicks So that he will be directed to those websites.
Sample Query:
Select * from table1 where url_Word like '%Search_String'
This will be the procedure that you need to follow to complete your work.
You do not need a database you need a text file. If this is a school project you need more information.