Reading Sharepoint List Calculated field from PowerShell - list

I am trying to pull data from a SharePoint list. The field is a calculated column that takes a yes or no answer and changes the words to archived and non-archived.
I can see the data being formatted correctly in the calculated column in IE but when I try to pull the data it shows up as nothing when I check the variable data.
$site = get-spsite https://extranet./sites/site
$web = get-spweb -Identity https://extranet/sites/site
$list=$web.getlist("https://extranet/sites/site/lists/List");
$View = $list.Views["LISTVIEW"]
$listitems = $list.Getitems($view)
foreach ($listitem in $listitems) {
I have tried this also but get an indexing a null variable error.
$mailboxdb = $listitem.Fields["mailboxdb"] -as [Microsoft.SharePoint.SPFieldCalculated];
$mailboxdb.GetFieldValueAsText($listitem["mailboxdb"]);
I see this also in the $listitems output. ows_MailboxDb='string;#Archived'
But when I check $mailboxdb its empty.
Found this but I don't know what it means by stored results.
In Powershell, although you can reference any field in the list in your script, you can only compare retrieve values from "static" fields - that is, you cannot use calculation fields. PowerShell will not complain - but you will not get results in your script. This is because the .Net library for Sharepoint will not do the field calculation for you - that only happens inside the Sharepoint UI itself.
If you need to have access to a "calculated" field, you actually need to have two fields - the calculated field (usually hidden) and a "stored result" field, which must be updated from the calculated value in the last step of the "Update" workflow. Then you can use the "stored value" field in PowerShell - and also, incidentally, in View calculations in Sharepoint.

You basically have two options here. You can have Powershell do the calculation for you, which is probably the simpler of the two options given the basic nature of your calculation.
The second option, as mentioned at the end of your post is to create a new field which can store the result of the calculation. In your case, you could call it status. Then you would create a workflow that runs whenever a list item is updated or created that stores the results of the calculated field in the results field. This seems redundant to me if you have this field for no other reason than to use the value of the calculated field in a PowerShell script.

Related

How do I Loop through a multi-value People Field or Lookup field in SharePoint 2013 designer using REST

I have a multi-valued people picker and a multi-valued Lookup field that I need to read all the entries in a 2013 workflow. I know how to create a workflow that retrieves the data and iterate through each list item using REST and a dictionary. Given I'm iterating through each item, I need to now iterate through each multi-valued field.
In the past, I have done this using a loop iterator and a second dictionary entry representing the data in the multi-valued field, but I don't have access to this code anymore. I can use a loop and use the find function parsing through my responseContent, but this is not reliable since my reponseContent will have multiple records in it and I know it can be done using a second dictionary entry.
My REST query is:
_api/lists/GetByTitle('EmailSetup')/Items?$select=EmailYN,EmailSubject,EmailBody,EmailTo/EMail,Emailcc/EMail,EmailToWorkflowPerson/Title,EmailccWorkflowPersons/Title&$filter=(Title%20eq%20%27BSM%20Review%27)%20and%20(WorkflowName%20eq%20%27ProcessBSMRequests%27)&$expand=EmailTo,Emailcc,EmailToWorkflowPerson,EmailccWorkflowPersons
Where my multi-valued fields are the Emailcc and EmailccWorkflowPerson, (people picker and lookup respectively).
I have my first dictionary as the following data structure that captures the requestHeaders
Accept String application/json;odata=verbose
Content-Type String application/json;odata=verbose
In my first loop I get all my attributes, but not certain how to get the multi-valued fields Emailcc and EmailccWorkflowPersons.
Yes, I can parse through my response, but there's a better way to somehow put these multi-value fields into a structure and then loop through these.
What I need is what is that structure (dictionary) and how do you get the data into that structure and then how do you loop through that structure.
The final result should be of the sort (psuedocode) where Index is which record I am on and Index2 is which multi-value I am on.
d/results([%Varaible: Index%])/Emailcc/Email[%Variable: Index2%])xxx
With a lot of debugging I have gotten half my answer and maybe someone can help me with the other half. The data structure of the data when it comes back via the REST looks like (some masking of our own data):
responseContent={"d":{"results":[{
"__metadata":{"id":"Web\/Lists(guid'c7bb71c8-a9dd-495f-aa5f-4dcacdf8db5c')\/Items(1)","uri":"https:\/\/xxxxx.xxxxxx.xxxxxxxxx.xxx\/hc\/teams\/MES\/_api\/Web\/Lists(guid'c7bb71c8-a9dd-495f-aa5f-4dcacdf8db5c')\/Items(1)","etag":"\"13\"","type":"SP.Data.EmailSetupListItem"},
"EmailTo":{"__metadata":{"id":"b493bee4-ec1a-4b76-a028-11766bdb7e5b","type":"SP.Data.UserInfoItem"},"EMail":"xyxee.dyff#homeward.com"},
"EmailToWorkflowPerson":{"__deferred":{"uri":"https:\/ \/xxxxx.xxxxxx.xxxxxxxxx.xxx\/hc\/teams\/MES\/_api\/Web\/Lists(guid'c7bb71c8-a9dd-495f-aa5f-4dcacdf8db5c')\/Items(1)\/EmailToWorkflowPerson"}},
"Emailcc":{"results":[{"__metadata":{"id":"790a690a-515b-4d07-bba3-73bf325fbbed","type":"SP.Data.UserInfoIt em"},"EMail":"xyxee.dyffns1#homeward.com"},{"__metadata":{"id":"3d77e75c-5fa8-4df6-937c-97e572714843","type":"SP.Data.UserInfoItem"},"EMail":"xyxee.dyffr#homeward.com"}]},
"EmailccWorkflowPersons":{"results":[{"__metadata":{"id":"06582ed9-09 10-4932-9b43-0cfb072942c7","type":"SP.Data.WorkflowPersonsListItem"},"Title":"Assistant Administrator"},{"__metadata":{"id":"13d03566-1703-4550-a21f-08ea286d4940","type":"SP.Data.WorkflowPersonsListItem"},"Title":"Initiator"}]},
"EmailYN":"No",
"EmailSubject":"BSM Request # %%ID%%",
"EmailBody":"<div class=\"ExternalClass645790473F7D4B62BE6224DD7B93990F\">%%IDLINK%%<br><\/div><div class=\"ExternalClass645790473F7D4B62BE6224DD7B93990F\">and the BSM# %%ID%%<br><\/div><div class=\"ExternalClass64 5790473F7D4B62BE6224DD7B93990F\"><br><\/div>"
}]}}
I created another dictionary variable, EmailResults just as the first one to store the multi-value emailcc addresses.
Then the following Get:
Get d/results([%variable: Index%)/Emailcc/results from Variable:responseContent (Output to Variable: EmailccResults)
To get the record count, I use Count Items in the EmailccResults
I set my second index to start at zero and loop through the number baseed on the count in EmailccResults.
To set my intermediate email address (getting one value at a time from the mult-value People picker).
Get d/results([%variable: Index%)/Emailcc/results(%Variable: Index2%)/EMail from Variable: responseContent (Output to Variable: EmailCc)
then I increment the Index2 variable and go to the next record. This works perfectly.
Now my problem is I have a multi-value Lookup that is included in this query (see what the results are above). I attempt the same logic and I am successfully getting the count, but not the Title fields.
My get is:
Get d/results([%variable: Index%)/EmailccWorkflowPersons/results from Variable:responseContent (Output to Variable: EmailccResults)
My actual assignment is:
Get d/results([%variable: Index%)/EmailccWorkflowPersons/results(%Variable: Index2%)/Title from Variable: responseContent (Output to Variable: tmpvar)
** the Lookup works exactly the same way. My problem was that my get above had some blank lines in the text box.

Mapping user spreadsheet columns to database fields

I’m not sure where to start on this project. I know how to read the contents of the excel spreadsheet, I know how to identify the header row, I know how to loop over the contents. I believe I have the UX portion worked out but I am not sure how to process the data.
I’ve googled and only found .Net solutions but I’m looking for a ColdFusion/Lucee solution.
I have a working form allowing me to map a user's spreasheet column to my database values (this is being kept simple for this post; user does not have direct access to the database).
Now that I have my data, I'm not sure how to loop over the data results. I believe there will be several loops (an outer and an inner). Then of course I also need to loop over the file contents but I think if I can get the headings mapped out,I can figure out the remaining.
Any good links, tutorials, or guides would be greatly appreciated.
Some pseudo code might be enough to get me started.
User uploads form
System reads headers and content.
User is presented form with a list of columns from their uploaded spreadsheet to match with available database fields (eg “column1” matches “customer name”.
User submits form.
Now what?
UPDATED
Here is what the data looks like AFTER the mapping has been done in my form. The column deliiter is the ::: and within the column the ||| indicates the ID associated with the selected column value. I've included the id and the column value since I plan on displaying the mapping again as a confirmation. Having the ID saves a trip to the database.
If I understand correctly, your question is: how do you provide the user a form allowing them to map their spreadsheet columns to that of the database
Since you have their spreadsheet column names, and you have the database column names, then this problem is essentially a UI/UX problem. You need to show both lists, and allow the user to map them. I can imagine several approaches to this. My first thought would be some sort of drag/drop operation, as follows:
Create a list of boxes, one for each field in your database table, and include the field name in (or above) the box. I'll call this the db field list. Then, create another list for each column from the spreadsheet, which I'll call the spreadsheet column list. The user would drag/drop items from the spreadsheet column list to the db field list.
When a mapping has been completed by the user, you would store the column/field names in as data for the DOM element of the db field list box. Then upon submission, you would acquire the mapping data by visiting each box and adding it to an array. Then you would serialize that array into JSON and send that to your form submission handler.
This could be difficult or easy, depending on your knowledge of UI implementations using JavaScript. jQuery makes this easy (if you know jQuery). There's even a jquery UI plugin that does this: https://jqueryui.com/droppable/.
A quick search for javascript drag drop would help, and here's a few articles I found:
https://www.w3schools.com/html/html5_draganddrop.asp
https://medium.com/quick-code/simple-javascript-drag-drop-d044d8c5bed5
You would also need to submit the array of mappings using javascript. You could search for that as well, and here's an article I found:
https://codereview.stackexchange.com/questions/94493/submit-an-array-as-an-html-form-value-using-javascript

Get part of django model depending on a variable

My code
PriceListItem.objects.get(id=tarif_id).price_eur
In my settings.py
CURRENCY='eur'
My Question:
I would like to pick the different info depending on the CURRENCY variable in settings.py
Example:
PriceListItem.objects.get(id=tarif_id).price_+settings.CURRENCY
Is it possible?
Sure. This has nothing to do with Django actually. You can reach the instance's attribute through pure Python:
getattr(PriceListItem.objects.get(id=tarif_id), 'price_'+settings.CURRENCY)
Note it might be a better idea to have a method on the model which accepts the currency as a parameter and returns the correct piece of data (through the line I wrote above, for example).
I think this should work
item = PriceListItem.objects.get(id=tarif_id)
value = getattr(item, price_+settings.CURRENCY)
In case you are only interested in that specific column, you can make the query more efficient with .values_list:
my_price = PriceListItem.objects.values_list_(
'price_{}'.format(settings.CURRENCY),
flat=True
).get(id=tarif_id)
This will only fetch that specific column from the database, which can be a (a bit) faster than first fetching the entire row into memory, and then discard all the rest later.
Here my_price is thus not a PriceListItem object, but the value that is stored for the specific price_cur column.
It will thus result in a query that looks like:
SELECT pricelistitem.price_cur
FROM pricelistitem
WHERE id=tarif_id

Podio API - Python filter request

Running pypodio2
I am trying to build a simple script which pulls a set of filtered items with the item filter command. It is for my own personal use to automate invoice generation.
My end game is to filter by a calculated date field - i.e. the field pulls a date from relationship.
However so far can't seem to get my request to filter any values at all. The is a sample of what I would expect to pull all items in the app where the quantity-kg value is 10.
c.Item.filter(14928728,attributes={'filter_by':[{"quantity-kg":10}]})
This returns all the items in the app.
I have tried a few different things but can't seem to work this out.
So first I would like to work out the correct syntax for passing simple request, and then work out how to pass a request to filter by date.
Worked it out, my original code had some mistakes.
'filters' not 'filter_by'
No need to pass a list as the attributes values
Filter values need to be in 'from' 'to' from.
So the code is:
c.Item.filter(14928728,attributes={'limit':500,'filters':{'121293716':{'from':'2‌​016-08-09','to':'2016-08-09'}}})
for the dates, or
c.Item.filter(14928728,attributes={'limit':500,'filters':{'quantity-kg':{'from':‌​10,'to':20}}})
for the value field.

Explicit correspondence between Google spreadsheet cells and Google form input fields

I am making a web form for people to sign up for an event. I found that I can use Google form and Google spreadsheet for this task, and I started to learn how to use these web applications. I would also like to send the automatic confirmation e-mail to those who have signed up. For this task, I am also looking into the Google Apps Script. As far as I understand, I should define a function to send e-mail in a script in the spreadsheet and trigger this function at 'Form Submission Event'. I would like to identify the e-mail address of a person who signed up from the data he/she submitted, and I would like to include all the submitted data as well as the time stamp in the confirmation e-mail.
My questions are the following.
How can I identify the cell in the spreadsheet into which the value of an input field in the Form is stored?
Or, is there any way that I can read the values of the respective input fields from a Google Apps Script?
I would be glad if you could kindly refer me to an unambiguous API reference related to these questions.
So far I learned about the applications from the help pages provided in Google Drive,
e.g.
https://developers.google.com/apps-script/overview
However, I feel documents there are too concise.
I am learning how to send confirmation e-mail from this Google Apps Script:
FormSubmissionResponseEmail
I could not find a help document that explicitly relates an input field in a Google form and a cell in the Google spreadsheet. From my limited number of experiment cases, it seems that the time stamps are always stored in the first column of the spreadsheet. Is this guaranteed? It seems that 'namedValues' member of the 'Spreadsheet Form Submit Events' class is said to contain "the question names and values from the form submission." (https://developers.google.com/apps-script/understanding_events)
However, when I modified the Google form, the 'namedValues' member still held the elements corresponding to deleted input fields. Is there any way to loop over only those elements in 'namedValues' that corresponds to the fields actually input by a user?
I would also be glad to hear about alternative tools to replace Google form and Google spreadsheet.
This answer applies to the "new Forms", the 2013 version, not "Legacy Forms" which have been discontinued.
How can I identify the cell in the spreadsheet into which the value of
an input field in the Form is stored?
You can identify the column that will collect answers to a form question by the label in row 1. Armed with that knowledge, you can reference the answers by column number in functions such as getRange().
...is there any way that I can read the values of the respective input
fields from a Google Apps Script?
There are multiple ways to reference input values:
As you found in Understanding Events, using a function triggered by Form Submission you can retrieve input values from the event itself. Two options here; you get a set of values in an array, and namedValues that you can reference using the question text as a name.
You can read the data from the spreadsheet; within that same trigger function mentioned earlier, you could use e.range.getValues() to get an array with all the submitted values, which you could then reference by index. Remember that this would be a 0-based array, while the column numbering starts at 1.
From my limited number of experiment cases, it seems that the
timestamps are always stored in the first column of the spreadsheet.
Is this guaranteed?
Unless you modify the spreadsheet, the timestamp will be in the first column. It is possible to insert columns to the left of the data table created by Forms, which will affect where you would find your form results in the sheet (although e.range will adjust). The order of all following values will be the order that the questions were created in the form. Note that if you delete a column (because you removed the question from the form, say), the column for the "deleted" question will be recreated at the end of the row.
...when I modified the Google form, the 'namedValues' member still
held the elements corresponding to deleted input fields. Is there any
way to loop over only those elements in namedValues that corresponds
to the fields actually input by a user?
There are reasons for remembering past questions, although they are just a bother when they weren't used to collect any real data. Better planning can be used to avoid the problem!
Unanswered questions will be empty strings in the event (e.g. e.namedValues["Dead Question"] == ''). So you could skip them like this:
for (var ans in e.namedValues) {
if (e.namedValues[ans] != '') {
doSomethingWith(e.namedValues[ans]
}
}
Note, too, that you can get array of "headers", or the form questions, like this:
var sheet = SpreadsheetApp.getActiveSpreadsheet();
var headers = sheet.getDataRange().getValues()[0];
...and then use a search of headers to find the column containing the answer you're looking for.