I have created 2 lists :
CarInfo(Custom List)
Car Booking(Calendar List)
I created columns like CarName and CarNumber. When I select CarName, CarNumber, it automatically comes, but, my requirement is, when I select CarName , StartTime and EndTime. For example:
Suppose CarName is Car1 , StartTime is 1:00pm and EndTime is 2:00Pm. Another user can login and add same car and timings.If another user can give same things, it wont allow those fields.
Here, I need validation for those columns. Can anyone help me.
What you can do is to write an ItemAdding Event Handler to the list definition using VS2010.
ItemAdding Event Handler
In the event hanlder, you will have to loop through the list checking if there is a matching item already.
You can use this code to get the values of the item that is to about to be added.
string jobTitle = properties.AfterProperties["Title"].ToString();
To cancel the job if item already exists
properties.Cancel = true;
Use this link to get an idea...
Creating SharePoint 2010 Event Receivers in Visual Studio 2010
Related
I'm stuck with an x-file trying to do something simple that I did thousands of times but now fails in a weird way.
I have a parent form called TASKS and a subform called TASKS_LIST. They are populated with recordsets that share some fields. The two important fields here are BUNDLE_ID (long) and TASK_ID (long).
Depending on certaing condition I want to link the subform with the parent form by the field BUNDLE_ID or by the field TASK_ID.
This is how I do it ->
First, in another form, I open the TASKS form like this:
DoCmd.OpenForm "TASKS", , , mVntCrit, , , intType
Where mVntCrit filters the records in the form and intType is an int with two possible values (1,2) passed by as an openArgs.
Then, on the Form_Open event of the parent form I do this:
Dim intTypeAs Integer
intType= Nz(OpenArgs)
Select Case intType
Case 1
Me.TASKS_LIST.LinkChildFields = "BUNDLE_ID"
Me.TASKS_LIST.LinkMasterFields = "BUNDLE_ID"
Case 2
Me.TASKS_LIST.LinkChildFields = "TASK_ID"
Me.TASKS_LIST.LinkMasterFields = "TASK_ID"
End Select
When I execute the code it appears an error message on the instructions that changes the linked fields:
Runtime Error '2101'
The specified value is not valid for this property.
I've tried/checked:
Initialize first the property values with an empty string to reset
the linking fields.
Change the order of the instructions, changing the value of the LinkMasterFields property first (althoug in principle the child goes first).
Compile, compact and repair.
Checked that the fields to link are the same type and have no nulls.
Checked that the fields name are correct.
What am I doing wrong? What am I missing?
Thanks a lot.
I found the issue.
I realized that the code worked for some records and failed for other records. So I needed to know what's different between the records that work and those than do not work.
Ok, in the original form that opens de TASKS parent form, there is a list of elements from a table T1. In the TASKS and TASKS_LIST forms the table T1 joins with a table T2 by a field F.
When I open the TASKS form, I filter its records with a certain criterion being F=Some Id from T1. The thing is: there are some records where this Id exists in T1 but not in T2. Therefore, when I open and filter the TASKS form with an Id that does not exists in T2 the form return no records. If TASKS do not return any records, TASKS_LIST do not return any records either.
In that case, when TASKS_LIST return no records, if I try to meddle with properties of the form (in this case .LinkChildFields and .LinkMasterFields) an error happens. On the other hand, when TASKS_LIST return some records, I can alter the form properties without problem.
Therefore I deduce that accessing and altering some properties of forms that return no records is forbidden for some reason. It reminds me of the classic error when trying to access the value of a texbox in a form without records.
I am having issues with setting a Validation rule in Access.
I have a database with the tables Clients, TypeClient, Sales, SalesList, Items.
I have a form for Sales, with a sub-form SalesList inside which has a relationship with Items in order for me to put several stock items in Sales instead of only one item.
Inside Sales table is ID, Date Sold, ID Client.
Inside SalesList is ID_List(referenced to ID in Sales), ID_Item(referenced to ID in Items), Quantity.
Inside Items is ID, Name, Stock(how much we have in stock), Price
The issue is that I am trying to validate the data I enter in the sub-form Quantity field to be higher than 0, but no higher than the available stock.
The issue is that I have tried using the expression builder to get the value from a calculated query that has 2 fields - the ID and the value for that id, with criteria that is for the ID to get it from the main form, the sub-form, the combo box input and the query works.
But when trying to get it like this:
It shows an error "The expression [Query bla] you entered in the form control's ValidationRule property contains the error The object doesn't contain the Automation object 'Query bla'".
I tried using directly the table Value(but it won't work anyway as it doesn't know for which field to get the stock value from), still the same error. I guess it can't reference to anything else? Normal validation rules work, but I want to validate it not to exceed the value of the available stock for the item I am selling now.
Nowhere on the internet there is a tutorial how to do it with expression builder. How do people validate their fields then?
It doesn't stop me in this case to sell 200 items when I currently have stock of only 2 of them, for example.
Note: I have tried DlookUp in expression builder, straight up tells me No.
Sample wrong validation rule expression builder code:
<=[Query bla]![Stock]
<=[Items]![Stock]
I am currently using VBA and fetch the record I need(the current stock) with one of the following and my unbound text is changing on every subform to the same, it shouldn't happen like that. What can I use to populate a field for each record uniquely:
Private Sub ID_Product_IZBOR_Click()
'Me.Stock_ValueField = DLookup("[Nalichnost]", "Stoka", "[ID]=" & Me.ID_Product_IZBOR)
Me.Stock_ValueField = Me.ID_Product_IZBOR.Column(2)
End Sub
Partial solution: I created a new Dim as Integer and fetched the records based on the ID provided by the field in the form and used BeforeUpdate to validate the current stock. Unfortunately the only way to see the current stock level is to click on the combo box where you choose your product and check the column for that one, it doesn't show anywhere else :(
Don't use the expression builder (I NEVER do) - just type the needed expression in property.
>0 AND <=DLookup("Stock", "Items", "ID=" & [ID_Item])
Another approach is to return Stock in textbox ControlSource then ValidationRule references that textbox. Also, user can then see the quantity limit. Methods of pulling the Stock value from Items table:
include Stock field in Items combobox RowSource - textbox then references column by its index (index begins with 0): =[cbxItems].Column(2); VBA may be needed to Requery combobox after record entry/edit is committed to table.
include Items table in form RecordSource - bind textbox to Stock field (Locked yes and TabStop no)
DLookup() expression in textbox ControlSource
Use ValidationText property to give users a custom message.
However, ValidationRule will not prevent user not entering any value if they skip the control. If you want to make sure a value is entered, either set field as required in table or use form BeforeUpdate event to validate record data.
I've got an InfoPath form and have set up a Data Connection to enable me to retrieve details of a persons account using the people picker.
I've got the First Name/Last Name/Department and Job Title. When I open up the People Picker the only fields I'm getting are Display Name/AccountId and Account Type (as pictured).
Is there a way of getting the information I want?
You can try to get it with the UserProfile webservice of sharepoint. (_vti_bin/UserProfileService.asmx)
f.e:
https://blogs.technet.microsoft.com/anneste/2011/11/02/how-to-create-an-infopath-form-to-auto-populate-data-in-sharepoint-2010/
For anyone still looking for an answer to this:
Unfortunately the UserProfile webservice no longer works in Sharepoint online and produces error 5566.
The best work around for this I've found would be to use a data connection to the hidden User Information List on the root of your page.
So step-by-step:
Add a new data connection for User Information List at the stem of your site
Select the needed fields (in your case First_name, Last_name, Department and Title)
Leave "Store a copy of the data in the form template" unchecked and click "Next >"
Uncheck "Automatically retrieve data when form is opened" to query based on selected users, instead of downloading all user data
Create Rule on change (no condition) on your First and Last Name fields and run the following actions in them:
Set a field's value for first and last name:
in "Field" select queryFields First_name/Last_name of your data connection
in "Value" select your first/last name field
Query using a data connection your Sharepoint List data connection or to User Information List data connection to find any user in the members AD group
Set a field's value on your people picker:
in "Field" select the Displayname of your forms people picker (only available in advanced view)
in "Value" select the dataFields > People Picker > Displayname of your data connection
Hope that helps, I'll edit to include pictures soon.
Please let me know if you wanted to set First name, Lastname, Department and Job title based on the people picker, because this would also be possible. Thank you in advance!
This is my first post, but often view this site to solve issues. Unfortuantely I have not been able to come up with a solution for my current development. I am working on a Task list with a different type of setup. The main form is a one stop shop for multiple users.
There are two tables
Team
- ID (autonum)
- First Name (text)
- Last Name (text)
- Full Name (Calculated)
Tasks
-ID (autonum)
- Task (short text)
- Description (Long Text)
- Start Date (short date)
- Assigned To (Lookup to Full Name)
- Etc (Additional fields)
The MainMenu (main form) is set up bound to the Team table. With a dropdown field to select a team member. The form has two subforms (CurrentTaskSub and NewTaskSub). Both Subforms are bound to Tasks. CurrentTaskSub is created from a query of Task where tasks are not complete and past the start date. NewTaskSub is a direct form of the task table.
When a name is selected it uses a parent/child relationship to filter the CurrentTaskSub to tasks assigned to that team member. That part works.
What I want to happen is when you select one of the tasks from CurrentTaskSub, it will populate in NewTaskSub to view all the info on the task and to change or update it. Then it will refresh both Subforms when a change is save in NewTaskSub whether that is completing a task, updating it, or creating a new task.
Here is what I have attempted:
On the CurrentTaskSub subform I select the task field and set that on click it will execute VBA code.
the current code of many I have tried is:
Forms!MainMenu![NewTaskSub].Form.Filter = "[Task] = " & Me.Task
Forms!MainMenu![NewTaskSub].Form.FilterOn = True
and
'With Forms(NewTaskSub).Recordset
'run a findfirst against that recordset
'NewTaskSub.FindFirst "[Task] = " & Me.Task
'if item not found issue warning
'If NewTaskSub.NoMatch Then MsgBox Me.Task & " not found"
'End With
Both these produce debug errors. I think I am on the right track but can seem to find the solution I am hoping for. Any assistance or advice is appreciated. Thank you.
Ok So after continued testing I have figured out the issue.
It was a minor problem and didn't need a lot of what I tried.
I am leaving this up though for others who may have similar issues.
I had to take the filter and add a requery so for this instance the code looks like this:
Me.Parent.Form.NewTaskSub.Form.Filter = "[ID]= " & Me.ID
Me.Parent.Form.NewTaskSub.Form.FilterOn = True
Me.Parent.Controls!NewTaskSub.Form.Requery
I have a SharePoint Designer workflow in 2010. This workflow is associated with a list and when it is run, should copy the Current Item back into the list then update a field in that newly created item with a variable set at initiation of the workflow. Basically it duplicates an item then changes 1 value of the newly created item.
The field that I need to update is a lookup field into another list. For some reason SharePoint does not like this and errors out each time.
I have tried setting the value of the field to the following things, all of which fail when run.
ID of the lookup item
ID;#VALUE of the lookup item
VALUE of the lookup item
1;#201101 which is a hardcoded value I know is correct...just trying to test here
At this point, I am out of ideas. Can anyone help?
For more detail the workflow has 1 step with the following actions:
Copy item in Current Item to list at [Parameter:ListURL], Do no Overwrite existing items. Store resulting list item id in [Variable:DuplicateID].
then set [Variable:Reporting Month ID] to [Reporting Months:ID]. (this is a lookup into Reporting Months list using variable [Variable:Reporting Month] which is set at initiation of workflow).
then Update item in Current List (the item is determined by [Variable:DuplicateID] and I try to set the value of the Reporting Month field in Current List using various combinations [Variable:Reporting Month ID] and [Variable:Reporting Month]
The error I get when the worflow is run is below.
The workflow could not update the item, possibly because one or more columns for the item require a different type of information.
Have had now the same problem and it seems that this is an spd-bug. I also wanted to write back the "variable: create" with the id of the destination-item into the lookup-field in the target-list. I also got always the same error. have checked the value also by updating a comment-field with this value and it was an integer value. but I could not update the lookup-value.
My solution for it:
Create a second workflow in the destination list that "update list item" in the target-list (update the lookup-value with the id of the current item) and define that the workflow starts automaticly by creation.
That worked fine for me. It needed some seconds more till the lookup-value was visible but this was not a problem for me.