But, there is option for inserting javascript (and jQuery) directly on the page, and, with javascript, you can do almost anything.
SCENARIO:
Let's say that we have one Custom Field called "Employee" that reads values from Lookup Table (values "Yes" and "No") and another Custom Field (plain text field) called "Work Place".
Let's say that we want to set field "Work Place" as readonly if user in field "Employee" selects value "No".
First, HTML Web Part needs to be added on Project Detail Page (Site Actions --> Edit Page --> Add a Web Part).
Just copy the following script into that Web Part that executes our scenario:
<script src="http://code.jquery.com/jquery-latest.js" type="text/javascript"></script>
<script src="http://code.jquery.com/jquery-migrate-1.0.0.js" type="text/javascript"></script>
<script>
$(document).ready(function(){
//first, we need to attach "onchange" event to "Employee" field, so each change of "Employee"
//field field will trigger our function
var projectType =document.body.getElementsByTagName("INPUT");
for (i=0; i < projectType.length;++i)
{
if(projectType[i].type=="text")
{
if(projectType[i].title=="Employee")
{
projectType[i].setAttribute("onchange", function(){MakeReadOnly();})
}
}
}
//this call triggers on every refresh of the PDP
MakeReadOnly()
});
function MakeReadOnly()
{
var inputs=document.body.getElementsByTagName("INPUT");
var fieldWorkPlace;
var isEmployee = true;
for (i=0; i < inputs.length;++i)
{
if(inputs[i].type=="text")
{
if(inputs[i].title=="Employee")
{
if(inputs[i].value == "No")
{
isEmployee = false;
}
}
if(inputs[i].title=="WorkPlace")
{
fieldWorkPlace= inputs[i];
}
}
}
//if "No" is selected, then disable field
if(isEmployee == false)
fieldWorkPlace.disabled = true;
else
fieldWorkPlace.disabled = false;
}
</script>
This comment has been removed by a blog administrator.
ReplyDeleteWhy you removed my Comment Sir? Am i fake? No. I,m Original Follower of Blogs.
ReplyDeleteSorry Juanid, I removed it automatically because I thought that it is spam (since it wasn't related to the topic of the post). But, I've visited your blog afterwards and I've found some very useful tips there and I am visiting your blog on a daily basis. Thank you for your comment and all your help. I can't restore your deleted comment.
ReplyDeleteThank a lot Mario! I usually visit your blog. But I had noticed your reply. You have great content. I know it's not my field. But I,m interested to learn languages as well. And I think your best one. Well, why don't you think to visit my new blog SEO and Blogging and comment on your favorite SEO tips. I,ll be grateful to see you there. I,ll wait for you Mario!
DeleteRegards
Junaid Raza
Great Mario!
ReplyDeleteYour script is working properly. Hope to see your again soon with a wonderful content.
Thank you. I'm glad that it helped.
DeleteThat's amazing Mario!! Good job!
ReplyDeleteFollowing this example, could be possible to force value on a custom field depending of a value in another custom field. Example, imagine that on this example that you exaplined I want to change the value on Workplace depending of Employee value. Thanks a lot man!!
Yes, it is possible. You can set value in textbox with similar javascript, but you must save changes before you leave page if you want that value to be saved. But, there is a different solution, if you can do this in code behind, there is a solution in code behind:
Deletehttp://sharepoint1on1.blogspot.com/2013/01/project-server-update-custom-lookup.html
will this work in project 2013? when I try this I get the following messages
ReplyDelete"Cannot retrieve properties at this time" and then "Cannot save your changes". Any idea?
Try to debug the solution and see on which line does it throw exception.
DeleteI don't see any issues with the solution, it throws an error when I add this code to the source editor on the HTML webpart which I add in PDP page for project server 2013.
DeleteWell, I don't know how to help you since I don't have Project Server 2013 and I can't replicate this error. Try asking question on Microsoft forum
DeleteActually I found a much simpler way of making a field read only:
ReplyDeletehttp://technicaltrix.blogspot.dk/2014/09/project-server-read-only-custom-fields.html
However if you need some logic on the read only thoggle the JavaScript solution is really nice.
Thanks Christian for the link. It is good solution if you just need readonly field. But, if you need your filed to be readonly depending on some other condition, then you need to use javascript.
DeleteHi Mario, my requirement is quite similar to this. On the change of one Text Custom Field without lookup, I want to change the other Date Custom Field to today's (current) date. Can this be a possibility via java script?
ReplyDeleteThanks
Hello Shravan, I have never tried to update field with javascript, but it is possible. Search for Javascript Object Model for Project Server (JSOM):
Deletehttps://msdn.microsoft.com/en-us/library/jj163037.aspx
Here you can find some examples:
http://blog.neos-sdi.com/post/Project-Server-2013-edit-Project-Custom-fields-from-Project-Center-%28English-Version%29.aspx
Hi Change event is not getting fired on employee text box can you please suggest
ReplyDeleteThis solution is tested in Project Server 2010 and "onchange" event fires every time. Are you testing it in your browser using developer tools?
DeleteHi Its getting fired on form load but when i click the values in look up table change event is not getting fired.Please suggest.
ReplyDeleteIt looks like the problem is in this line:
DeleteprojectType[i].setAttribute("onchange", function(){MakeReadOnly();})
I am not sure how to help, but try something else instead of "setAttribute", maybe with attr() method
I think my textbox is read only when i click the button beside textbox it will expand a llokup table.We can able to select values only form the look up table.thats why onchnage function is not working i think.
Delete