0

I have a new form for a SharePoint list. this form should set some value through code. I'm using SharePoint on-premises 2019 designer new form.

HTML code of the new form element:

<tr style="visibility: hidden;">
    <td width="190px" valign="top" class="ms-formlabel">DStatus</td>
                                                                                                                                                               
       <SharePoint:FormField runat="server" id ="ff32{$Pos}" ControlMode = "New"       FieldName="DRStatus" __designer:bind="{ddwrt:DataBind('u',concat('ff32',$Pos),'Value','ValueChanged','ID',ddwrt:EscapeDelims(string(@ID)),'@DRStatus')}"/>
                                                            
        <SharePoint:FieldDescription runat="server" id = "ff32description{$Pos}" FieldName="DRStatus" ControlMode="New"/>
        
</td>
</tr> 

JS code to set value:

 var status = $('#Lookup id');
       var statusOption = status.find('option:eq(1)');
       var selectedStatus;          
       selectedStatus= statusOption.text(); 
       alert("DRStatus: " +selectedStatus);
        
       $("input[Title='DRStatus']").val(selectedStatus);

I have tried the approach below. It can extract the values if the column was a lookup. But cannot set/save the value for the column element in list.

Please help, how can I set the column element value directly through code without using workflow?

5
  • Are you using the classic experience list form? Commented Apr 3 at 7:29
  • no, im using modern expirience for the form Commented Apr 3 at 9:28
  • You cannot inject custom JS directly for modern list forms. Commented Apr 3 at 9:36
  • I did not know that. Thanks for letting me know. Commented Apr 3 at 9:54
  • @GaneshSanap-MVP, is there any other way to set defualt/conditional value for new form elements Commented Apr 3 at 9:55

0

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.