How to Check User already created list items and enable other fields in New Item form?

adil 1,431 Reputation points
2021-06-24T19:47:21.757+00:00

I created a custom list with some fields & Users will fill enter the data. Custom fields: Employee Name Department City Change Department (Yes/No drop down) (disabled when the first entry in NewItem form) Reason

What I want that when the same user (logged in User) enters the data a second time here one Popup or message should show to the user and Enable the field 'Change Department' and when the user selects 'Yes', 'Reason' filed should be enabled and he will 'Save' the list item. In case 'No' User can not save the list item & 'Save' button not enabled for this user and he will only close the form.

Here

How I check the condition that when the same logged-in user already created a list of items?
and show the message to user & Enable Change Department field & based on the value of this field enable Reason field and Enable the Save button.

Microsoft 365 and Office SharePoint Server For business
Microsoft 365 and Office SharePoint Server Development
0 comments No comments
{count} votes

1 answer

Sort by: Most helpful
  1. MichaelHan-MSFT 18,126 Reputation points
    2021-06-25T03:00:08.147+00:00

    Hi, @adil

    You could use cutom code(Rest API) to check when the same logged-in user already created a list of items.

    Using the rest api to get the listitems created by current user, alert message if the items.length >0, for example:

    var userId = _spPageContextInfo.userId;  
    var requestUri = _spPageContextInfo.webAbsoluteUrl + "/_api/Web/Lists/getbytitle('ListName')/Items?$filter=AuthorId eq " + userId;  
    $.ajax  
        ({  
            url: requestUri,  
            type: "GET",  
            headers: {  
                "ACCEPT": "application/json;odata=verbose"  
            },  
            success: function (data) {  
                if ($(data.d.results).length == 0) { }  
                else { //popup message here }  
            },  
            error: function () {  
            }  
        });  
    

    If an Answer is helpful, please click "Accept Answer" and upvote it.
    Note: Please follow the steps in our documentation to enable e-mail notifications if you want to receive the related email notification for this thread.


Your answer

Answers can be marked as Accepted Answers by the question author, which helps users to know the answer solved the author's problem.