Sharepoint Updating MMS DocumentSet field - asp.net

I have am writing some SharePoint 2013 integration to my companies product, to upload a document set with metadata and then upload some documents.
I have all this functionality working correctly, except for updating Document Set metadata fields that require MMS (Managed Metadata Service) fields.
dim docSetUrl as string = "http://someurl/"
Dim folder = Context.Web.GetFolderByServerRelativeUrl(docSetUrl)
Context.Load(folder)
Context.ExecuteQuery()
folder.Properties.Item("GeoObject") = "test" 'Normal string content (updates correctly)
folder.Properties.Item("Applicant") = "1353;#: Value A : REC-95342|9074b95b-9dcd-4c93-b548-32a5c7e7e083" 'Does not update correctly
folder.Update()
Context.ExecuteQuery()
Now as you can see from the code, I can update the GeoObject which just requires a string value, but for the Applicant object which is a MMS type, it just doesn't change (no errors).
If I log into SharePoint and manually use MMS to select an item, and then programatically check what it's value is : 353;#: Value A : REC-95342|9074b95b-9dcd-4c93-b548-32a5c7e7e083, if I clear the value manually and then try to push the found value back in, I still have no result.
How am I supposed to update a MMS field?
Thanks,

I was able to piece this together via lots of input from different sources. Such as https://unnieayilliath.com/2015/08/24/sharepoint-2013-updateclear-taxonomy-field-value-using-c-csom/
Dim value As TaxonomyFieldValue = New TaxonomyFieldValue()
value.WssId = -1
value.TermGuid = terms.First.Id.ToString
value.Label = terms.First.Name
Dim list As List = folder.ListItemAllFields.ParentList
Dim field As Field = list.Fields.GetByInternalNameOrTitle("Property")
Dim txField As TaxonomyField = Context.CastTo(Of TaxonomyField)(field)
txField.SetFieldValueByValue(folder.ListItemAllFields, value)
folder.ListItemAllFields.Update()
Context.Load(folder.ListItemAllFields)
Context.ExecuteQuery()

Related

Lotus notes Formula. trying to run an #command inside of a fields validation

I am trying to use formula to open a document from within a field when it comes to validation. Basically i have set up a database that checks for duplicate entries and I want the database to (if a form is created) check that it doesn't already exist and if it does ask the user if it wants to open the form. I have got it all set up and acquired the UNID but when I come to save the document to test (with everything working perfectly) it gives the following error
#commands and other UI functions are not allowed in this context
Not sure what to try. Any help would be appreciate. The command I used is as follows
#Command([EditDocument];1;Unid) //where Unid is an ID I have acquired previously
This is a task, that cannot be done with formula language. As the message sais: #Commands cannot be used in any of the contexts that could help you with this task.
You need to use LotusScript in any matching event (e.g. QuerySave) to do this Check and open the other document. Here is some example code:
%include "lsconst.lss"
Sub QuerySave( Source as NotesUIDocument, Continue as Variant )
Dim ses as New NotesSession
Dim db as NotesDatabase
Dim ws as New NotesUIWorkspace
Dim doc as NotesDocument
Dim ok as Variant
Dim strOtherUnid as String
Set db = ses.CurrentDatabase
strOtherUnid = Source.Document.OtherUnid(0)
If strOtherUnid <> "" then
Continue = False
ok = Messagebox ("There is already another document, do you want to edit it?" , MB_YESNO + MB_ICONQUESTION, "QUESTION" )
if ok = IDYES then
Set doc = db.GetDocumentByUNID( strOtherUnid )
Call ws.EditDocument( False, doc )
End if
End if
End Sub
This code is not tested at all, just to be used as a starting point. It needs a field called "OtherUnid" that contains the universalid of the other document.

Entity Framework DB Not updating until project is rebuilt?

My project uses LINQ to SQL and EF to handle objects in the database. I have a status column in an entity object that is designated as an int. My BI layer updates this data with the below code, when i change the data, if i query SQL i see the updated value in the DB, however the UI layer is not displaying the new value, it shows the old one. Stopping the project in VS and re-starting it, then it will display the updated data.
Does EF do any caching? Could this be caused by having 3 seperate projects for Data, UI and BI?
Public Shared Function UpdateStatus(PersonID As Guid, Status As LeadStatus, UserName As String) As Boolean
Dim db As New MyDb.DBContainer
Dim z = (From p In db.People Where p.Id = PersonID).FirstOrDefault()
If Not IsNothing(z) Then
z.Status = Status
db.SaveChanges()
LeadLogFunctions.AddLog(LeadLogTypes.StatusChanged, PersonID, UserName, "Status Changed By: " & UserName & " To: " & Enumeration.GetEnumDescription(Status))
Return True
End If
Return False
End Function
The UI layer won't display the new value until you reload it from the database.
If you are keeping the same DbContext open, you should reload the existing entity rather than making a new query using the DbContext.Entry(of T)().Reload() function.

How to use SQL Server 2008 stored procedure in asp.net mvc

I have created a simple stored procedure in SQL Server 2008 as:
CREATE PROCEDURE viewPosts
AS
SELECT * FROM dbo.Post
Now, I have no idea how to use it in controller's action, I have a database object which is:
entities db = new entities();
Kindly tell me how to use stored procedure with this database object in Entity Framework.
For Details check this link:
http://www.entityframeworktutorial.net/data-read-using-stored-procedure.aspx
Hope this will help you.
See article about 30% in:
In the designer, right click on the entity and select Stored Procedure mapping.
Click and then click the drop down arrow that appears. This exposes the list of all Functions found in the DB metadata.
Select Procedure from the list. The designer will do its best job of matching the stored procedure’s parameters with the entity properties using the names. In this case, since all of the property names match the parameter names, it maps every one correctly so you don’t need to make any changes. Note: The designer is not able to automatically detect the name of the field being returned.
Under the Result Column Bindings section, click and enter variable name. The designer should automatically select the entity key property for this final mapping.
The following code is what I use to initialize the stored procedure, then obtain the result into variable returnedResult, which in this case is the record id of a newly created record.
SqlParameter paramResult = new SqlParameter("#Result", -1);
paramResult.Direction = System.Data.ParameterDirection.Output;
var addParameters = new List<SqlParameter>
{
new SqlParameter("#JobID", EvalModel.JobID),
new SqlParameter("#SafetyEvaluator", EvalModel.SafetyEvaluator),
new SqlParameter("#EvaluationGuid", EvalModel.EvaluationGuid),
new SqlParameter("#EvalType", EvalModel.EvalType),
new SqlParameter("#Completion", EvalModel.Completion),
new SqlParameter("#ManPower", EvalModel.ManPower),
new SqlParameter("#EDate", EvalModel.EDate),
new SqlParameter("#CreateDate", EvalModel.CreateDate),
new SqlParameter("#Deficiency", EvalModel.Deficiency.HasValue ? EvalModel.Deficiency.Value : 0),
new SqlParameter("#DeficiencyComment", EvalModel.DeficiencyComment != null ? EvalModel.DeficiencyComment : ""),
new SqlParameter("#Traffic", EvalModel.Traffic.HasValue ? EvalModel.Traffic.Value : 0),
paramResult
};
// Stored procedure name is AddEval
context.Database.ExecuteSqlCommand("AddEval #JobID, #SafetyEvaluator, #EvaluationGuid, #EvalType, #Completion, #ManPower, #EDate, #CreateDate, #Deficiency, #DeficiencyComment, #Traffic, #Result OUTPUT", addParameters.ToArray());
var returnedResult = paramResult.Value;
NewEvaluationID = Convert.ToInt32(returnedResult);

vb.net alternative to select case when dealing with object values

Hey all, I was able to do this via a SELECT CASE statement, however I'm always trying to improve my code writing and was wondering if there was a better approach. Here's the scenario:
Each document has x custom fields on it.
There's y number of documents
However there's only 21 distinct custom fields, but they can obviously have n different combinations of them depending on the form.
So here's what I did, I created an object called CustomFields like so:
Private Class CustomFields
Public agentaddress As String
Public agentattorney As String
Public agentcity As String
Public agentname As String
Public agentnumber As String
Public agentstate As String
Public agentzip As String
... more fields here ....
End Class`
Then I went ahead and assigned the values I get from the user to each of those fields like so:
Set All of Our Custom Fields Accordingly
Dim pcc As New CustomFields()
pcc.agentaddress = agent.address1
pcc.agentattorney = cplinfo.attorneyname
pcc.agentcity = agent.city
pcc.agentname = agent.agencyName
pcc.agentnumber = agent.agentNumber
pcc.agentstate = agent.state
pcc.agentzip = agent.zip ....other values set to fields etc.
Now the idea is based upon what combo of fields come back based upon the document, we need to assign the value which matches up with that custom field's value. So if the form only needed agentaddress and agentcity:
'Now Let's Loop Through the Custom Fields for This Document
For Each cf As vCustomField In cc
Dim customs As New tblCustomValue()
Select Case cf.fieldname
Case "agentaddress"
customs.customfieldid = cf.customfieldid
customs.icsid = cpl.icsID
customs.value = pcc.additionalinfo
Case "agentcity"
customs.customfieldid = cf.customfieldid
customs.icsid = cpl.icsID
customs.value = pcc.additionalinfo
End Select
_db.tblCustomValues.InsertOnSubmit(customs)
_db.SubmitChanges()
This works, however we may end up having 100's of fields in the future so there a way to somehow "EVAL" (yes I know that doesn't exist in vb.net) the cf.fieldname and find it's corresponding value in the CustomFields object?
Just trying to write more efficient code and looking for some brainstorming here. Hopefully my code and description makes sense. If it doesn't let me know and I'll go hit my head up against the wall and try writing it again.
If I am reading your question correctly, you are trying to avoid setting the value of fields, when the field isn't used. If so, I would recommend you just go ahead and set the field to nothing in that case.

3D Secure processing issue using dotnetcharge

I'm integrating a number of e-comm sites into different banks and decided the easiest method was to add in the dotnetcharge (www.dotnetcharge.com) library. It works well and means I can keep much of my code the same for each bank type and transaction. However, their support is a bit sucky (4 emails sent, 1 reply) and I'm utterly baffled on the 3D Secure issue.
Does anyone have experience with dotnetcharge and 3D Secure? I have set the MerchantURL and the actual 3D Secure screen comes up - but I'm unsure how to get the system to 'flow' properly. Does anyone have any code examples or even pointers in the right direction? Failing that, does anyone know how to make support respond!
This particular integration is with SagePay, which also has God-awful documentation and support.
Code for reference is as follows;
Dim Amount As Decimal = ordertotal
' ApplySecure3D options:
' 0 = If 3D-Secure checks are possible and rules allow, perform the checks and apply the authorization rules.
' 1 = Force 3D-Secure checks for this transaction only (if your account is 3D-enabled) and apply rules for authorization.
' 2 = Do not perform 3D-Secure checks for this transaction only and always authorize.
' 3 = Force 3D-Secure checks for this transaction (if your account is 3D-enabled) but ALWAYS obtain an auth code, irrespective of rule base.
Dim ProtxLogin As String = "xxx"
Dim ProtxPassword As String = "xxx"
Dim ProtxApply3DSecure As Integer = 1
Dim ProtxMerchantURL As String = "https://www.mydomain.com/processing/"
Dim Number As String = txtCardNo.Text '//luhn/mod10 here.
Dim AVS As String = txtCVN.Text
Dim DD As String = "01"
Dim MM As String = ddlValidTo_month.SelectedValue.ToString()
Dim YY As String = ddlValidTo_year.SelectedValue.ToString()
Dim ProcessingResult As Integer = 0
Dim Protx As New dotnetCHARGE.CC()
Protx.Login = ProtxLogin
Protx.Password = ProtxPassword
Protx.ApplySecure3D = ProtxApply3DSecure
Protx.MerchantUrl = ProtxMerchantURL
Dim AVSResponse As String = ""
Dim CVV2 As String = ""
Protx.OrderID = GoogleOrderNumber
Protx.Month = MM
Protx.Year = YY
Protx.TransactionType = dotnetCHARGE.TransactionType.Sale
Protx.Amount = ordertotal
Protx.Number = Number
Protx.Currency = "GBP"
Protx.CustomerID = CustomerId
'//loads of params removed for brevity
Protx.ClientIP = Request.UserHostAddress.ToString()
Protx.CardType = ddlCardType.SelectedValue.ToString()
Protx.Description = "My Order"
Protx.Code = AVS
Protx.TestMode = True
Protx.TransactionType = dotnetCHARGE.TransactionType.Sale
ProcessingResult = Protx.Charge(Processor.Protx)
Help appreciated.
I decided to return to this question to explain how the final result was acheived. Hopefully some SO users will find it useful.
To acheive the correct 'flow' you'll need two pages. You won't realistically be able to do the whole transaction processing in a single page. The first page will have the card entry details; card number, expiry date, CVN, billing address etc. On hitting pay/submit I'd recommend saving the transaction to your datasource as 'unprocessed' or something similiar. Once all your details are saved - no card processing done thus far - redirect with HTTPS to the second page.
Your customer may never know this page exist depending on how you set this up. The second page will have the .netCharge code within it as my question and process the card. When 3D secure is enabled (.Apply3DSecure = 1), the customer will be redirected to their bank to enter some further details and it will return to this second page. It doesn't behave like a postback or a refresh, so do not worry about a returning call to the page processing twice. You will receive 1 of 3 possible statuses; Authorised, Error and Declined. Your page can redirect to further necessary pages (therefore the customer nevers know this middle page exists) or display the results directly on this processing page.
There is one final 'gotcha', which you'll see very quickly. The second page (the processing page) needs the card details to actually process. You can't just pass card details on a form or even a querystring, that's irresponsible. .netCharge comes with an .Encrypt and .Decrypt function; just pass it the value to encrypt and a hash of some sort and save these details temporarily on the first page, read and decrypt on the second page and then remove them. This means the details are secure, are saved for less than 5 seconds in most cases and you have no exposure because they are destroyed.
I hope this helps - if anyone has any questions, just give me a shout.

Resources